Sunday, January 28, 2007

Qt and PostgreSQL on Windows

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.



zzz said...

Welcome back :)

Eng Liang said...

you have save me a lot of trouble, thanks...btw when is v.rossi going to win motogp again? by pohel

JapiTa said...

But what the hell is msjava.dll

JapiTa said...

My application does not use QTnetwork,
but the dependency walker says the contrary.
If I installa my exe on another machine, the exe fires a seg fault.
On my Pc, where the exe was compiled, no problems

Luca Bruno aka Lethalman said...

japita I'm really sorry but Im not using qt anymore. Though msjava.dll is not part of Qt, but I remember it must be in your system.

Tom said...

I've hunted high and low for a solution to the infamous "Driver not loaded" problem. There are hundreds of suggestions online but this is the only one that has helped me.

The crucial point seems to be the list of PostgreSQL dependencies that you list (other than the driver). I guess this list will change with platforms and versions. What I did was to copy all .dll files from my PostgreSQL installation (C:\Program Files\PostgreSQL\8.4\bin) to my development directory ([projectname]\debug\).

Many thanks!

Irving Montalvo said...

please can send or carry the qsqlpsql4.dll. I hope your answer

Anonymous said...

Thank you very much for that info. I was stuck for ages as my program couldn't connect to database even when I had all dlls in place. Only thing I was missing was create folder 'sqldrivers' and put plsql dll in it.

Thank you very much !!!!