Frage

i wrote a program that need to connect to database to insert some data , my executable file not connect to database but when i checked with code connection established! i don't know what is problem , do you know what is problem? i use Qt to connect to database and my database is on mySql and here is how i connect :

soccer_db = QSqlDatabase::addDatabase("QMYSQL" , "sss");
    soccer_db.setHostName(addrrFile.c_str());
    soccer_db.setDatabaseName("sss");
    soccer_db.open();
    if (!soccer_db.open()){
        emit dsignal("ssss not opened. Ckech whether server is down or change config file");
        return false;
    }
War es hilfreich?

Lösung 2

i want to answer my question, in qt you should address your files completely not relative address, if you need to address completely you can give current directory by QtDir

Andere Tipps

You are getting a failure because you try to open the database twice. The first attempt succeeds but the second one fails. Remove the first call to open, like this

soccer_db = QSqlDatabase::addDatabase("QMYSQL" , "sss");
soccer_db.setHostName(addrrFile.c_str());
soccer_db.setDatabaseName("sss");
if (!soccer_db.open()){
    emit dsignal("ssss not opened. Ckech whether server is down or change config file");
    return false;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top