Sunday, January 28, 2007

Qt and PostgreSQL on Windows

Hello,
in this period i'm creating a simple application with Qt/C++ and Postgres, but i got the usual error "Driver not loaded" when opening the database. This means the qsqlpsql sql driver can't be loaded.

First of all, you may need to compile the driver, this can be done by reading the Qt documentation on how to install sql drivers on windows. After i've done that, the error was the same: Driver not loaded.

The solution is simple, just put these files in the directory where your executable is:
- mingwm10.dll (for who's using MingW)

Ordinary Qt dependencies (found in the bin directory of Qt):
- QtCore4.dll
- QtGui4.dll
- QtSql4.dll

PostgreSQL dependencies (found in the bin directory of PostgreSQL):
- krb5_32.dll
- libeay32.dll
- libiconv-2.dll
- libintl-2.dll
- libpq.dll
- ssleay32.dll

Other dependencies that you maybe should download from internet:
- efsadu.dll
- msjava.dll

After that, your directory should contain the above DLLs with the executable file.
The next step is to create a directory named sqldrivers in the same directory and copy into qsqlpsql.dll from %QTDIR%/plugins/sqldrivers.

Now run your application and everything should work correctly.
In all mailing list i've seen that they needed to recompile Qt with qsqlpsql statically linked, but i adopted this other solution which is more suitable.

Bye.