문제

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