Bonjour,

Je me sers depuis peu de QT Creator sous mac et je rencontre un problème lors de la compilation de mon programme.

J'ai un premier projet de type bibliothèque qui contient la classe suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
H:
#ifndef BM2SLIB_SINGLETON_SQLUTILS_H
#define BM2SLIB_SINGLETON_SQLUTILS_H
#include <QSqlDatabase>
 
namespace bm2sLib {
namespace singleton {
class sqlUtil
{
public:
    static sqlUtil* getInstance();
    bool isReady();
    static QString text();
 
private:
    QSqlDatabase dbArticle;
    QSqlDatabase dbParameter;
    QSqlDatabase dbPartner;
    QSqlDatabase dbSell;
    QSqlDatabase dbUser;
    static sqlUtil *instance;
    sqlUtil();
};
 
}
}
 
#endif // BM2SLIB_SINGLETON_SQLUTILS_H
 
CPP:
#include "sqlutil.h"
 
bm2sLib::singleton::sqlUtil::sqlUtil()
{
    this->dbArticle = QSqlDatabase::addDatabase("QMYSQL");
    this->dbArticle.setHostName("192.168.0.1");
    this->dbArticle.setDatabaseName("Article");
    this->dbArticle.setUserName("bm2s");
    this->dbArticle.setPassword("");
 
    this->dbParameter = QSqlDatabase::addDatabase("QMYSQL");
    this->dbParameter.setHostName("192.168.0.1");
    this->dbParameter.setDatabaseName("Parameter");
    this->dbParameter.setUserName("bm2s");
    this->dbParameter.setPassword("");
 
    this->dbPartner = QSqlDatabase::addDatabase("QMYSQL");
    this->dbPartner.setHostName("192.168.0.1");
    this->dbPartner.setDatabaseName("Partner");
    this->dbPartner.setUserName("bm2s");
    this->dbPartner.setPassword("");
 
    this->dbSell = QSqlDatabase::addDatabase("QMYSQL");
    this->dbSell.setHostName("192.168.0.1");
    this->dbSell.setDatabaseName("Sell");
    this->dbSell.setUserName("bm2s");
    this->dbSell.setPassword("");
 
    this->dbUser = QSqlDatabase::addDatabase("QMYSQL");
    this->dbUser.setHostName("192.168.0.1");
    this->dbUser.setDatabaseName("User");
    this->dbUser.setUserName("bm2s");
    this->dbUser.setPassword("");
}
 
bool bm2sLib::singleton::sqlUtil::isReady()
{
    return this->dbArticle.isOpen() && this->dbParameter.isOpen() && this->dbPartner.isOpen() && this->dbSell.isOpen() && this->dbUser.isOpen();
}
 
bm2sLib::singleton::sqlUtil* bm2sLib::singleton::sqlUtil::getInstance()
{
    if(bm2sLib::singleton::sqlUtil::instance == 0)
    {
        bm2sLib::singleton::sqlUtil::instance = new sqlUtil();
    }
 
    return bm2sLib::singleton::sqlUtil::instance;
}
 
QString bm2sLib::singleton::sqlUtil::text()
{
    return "text";
}
Le second projet comporte une fenêtre de dialogue qui comporte deux champs de saisie. J'essaye d'en initialiser un des deux pour m'assurer que le code suivant fonctionne bien :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "connection.h"
#include "ui_connection.h"
#include "QSqlDatabase"
#include "sqlutil.h"
 
Connection::Connection(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Connection)
{
    ui->setupUi(this);
    QString text;
 
    // Début du soucis
    //text = "text";
    text = bm2sLib::singleton::sqlUtil::text();
    // Fin du soucis
 
    this->ui->UserName->setText(text);
}
 
Connection::~Connection()
{
    delete ui;
}
Ce code fonctionne lorsque je suis dans ce cas là :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
    text = "text";
    //text = bm2sLib::singleton::sqlUtil::text();
Mais pas dans l'autre cas, et je ne comprend pas pourquoi.
La librairie compile très bien.