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