简体   繁体   中英

QT´s generated exe cannot connect to PostrgreSQL Database

I´m developing an application in QT 5.4 that connects to a Postrgre DB. When Running the application in release mode inside QT Creator the connection works fine. However, when I add the dependencies of the .exe and open it I always get a connection error. I added the QT5Sql.dll to the release directory and all the other needed dependencies according to dependency walker.

Can anyone tell me what I´m doing wrong?

ui->setupUi(this);
finishedGame = false;
ui->detener->setVisible(false);
ui->labelEnCurso->setVisible(false);
db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("MYDB");
db.setUserName("USER");
db.setPassword("PASS");
bool ok = db.open();
if(!ok){

    QMessageBox msgBox;
    msgBox.setText("Connection ERROR");
    msgBox.exec();
}

UPDATE

I checked the .exe with DebugView and this is the error I get:

[10876] QSqlDatabase: QPSQL driver not loaded
[10876] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

I have both the libpq.dll and the qsqlpsql.dll on my release folder, however for some reason the app cannot load the appropriate drivers although it is saying it´s available.

I got it working. Just in case anyone comes across the same problem. I solved it by adding all the contents of the bin folder in the PostgreSQL installation Directory to my release folder of the QT project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM