質問

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;
    }
役に立ちましたか?

解決 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

他のヒント

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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top