PDA

View Full Version : Connecting to PostgreSQL using Qt



mikeb1997
12th October 2020, 23:44
Greetings all, I hope you're doing well.

I have found myself in a bit of a gap semester due to COVID, and I decided to brush up on my programming and learn Qt. I decided to build a toy application from start to finish that communicates with a PostgreSQL Database. I really like the signal/slot systems and the Core/GUI libraries, they're very useful. However, as soon as I tried to connect with my database, I ran into problems. First of all, my system is:

Windows 10, 64-bit
Qt 5.15.1
PostgreSQL 13, 64-bit
MinGW 8.1 64-bit
MSVC 2019 64-bit

The error, as you may have guessed, is the following:



QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7


After a bit of stumbling around in Google, I figured I needed to download the Qt source code and compile the driver (plugin) myself. I downloaded the source, navigated to the appropriate folder (I also copied the mingw qsqlpsql.dll files to that directory) and ran the following command:



C:\Qt\5.15.1\mingw81_64\bin\qmake.exe -- PSQL_INCDIR="C:/Program Files/PostgreSQL/13/include" PSQL_LIBDIR="C:/Program Files/PostgreSQL/13/lib" -sql-psql


This produced the following:



Running configuration tests...
Done running configuration tests.

Configure summary:

Qt Sql Drivers:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... no
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no

ERROR: Feature 'sql-psql' was enabled, but the pre-condition 'libs.psql' failed.

Check config.log for details.


As you can see, it cannot see the PostgreSQL driver. After checking config.log I found out that it's actually trying to use a 32-bit mingw, and it can't find most of the things it's looking for.

Honestly, I am quite lost at this point. There are many many people online with pretty much the same problem as me but I've tried all google results to no avail. Note that I've also (a) reinstalled Qt and PostgreSQL at least twice so far, (b) Tried to use MSVC instead of MinGW without success and (c) tried to copy all the dlls and libs in the sqldrivers folder.

I am unsure what to do next and I feel I've probably made a complete mess. Does anybody have any idea what I should do? Part of me feels like this shouldn't be that difficult and I am missing something fundamental. I very much appreciate and welcome any input or advice. Thank you.