Answer the question
In order to leave comments, you need to log in
How to build PostgreSQL driver for Qt under Windows 10?
It is necessary to create a minimally working Qt application for connecting and interacting with the PostgreSQL DBMS. Doesn't work out of the box. OS - windows 10 64bit, Qt version - Qt 5.9.5 MSVC 2015, MS Visual Studio 2017 Community, PostgreSQL 9.6 (tried both 32bit and 64bit) I
check with this code:
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
qDebug() << db.isValid();
db.setHostName("hostname");
db.setPort(5432);
db.setDatabaseName("dbname");
db.setUserName("username");
db.setPassword("password");
if (!db.open())
{
qDebug() << db.lastError().text();
return;
}
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
false
qmake "INCLUDEPATH+=\"C:\Program Files (x86)\PostgreSQL\9.6\include\"" "LIBS+=\"C:\Program Files (x86)\PostgreSQL\9.6\lib\libpq.lib\"" psql .pro
Project ERROR: Library 'psql' is not defined.
Project ERROR: Library 'psql' is not defined.
Cannot read /qtsqldrivers-config.pri: No such file or directory
Project ERROR: Library 'psql' is not defined.
Project ERROR: Library 'psql' is not defined.
Answer the question
In order to leave comments, you need to log in
It turned out to solve the problem with the help of Dependence Walker. Indeed, the problem was solved not by compilation, but by copying the necessary dlls to the folder with the program. Specifically, I copied libpq.dll, libeay32.dll, ssleay32.dll, libintl-8.dll, libiconv-2.dll, msvcr120.dll there, and the sqldrivers folder with dll from C:\Qt\Qt5.9.5\5.9. 5\msvc2017_64\plugins\sqldrivers. I only made sure that the bit depth matches, and everything worked.
the conclusion is incorrect. you don't need to compile the driver. you should include it in your code (but this is not accurate).
well, you must also have at least the postgresql client installed, and its directory with binaries must be included in the system PATH.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question