Qpsql Driver Not Loaded Qt

QPSQL driver not loaded Qt

I came here googling because I had the same problem in Windows.

In my case to solve the issue I had to install PostgreSQL for Windows 32 bits since my Qt target was MinGW 32 bits.

Additionally, I had to add the PATH to the PostgreSQL bin and lib directories so Qt could find the right .dlls.

@SET PATH=C:\Program Files (x86)\PostgreSQL\9.6\bin\;C:\Program Files (x86)\PostgreSQL\9.6\lib\;%PATH%

The PATH can be set before launching Qt Creator or using the Qt Creator itself via the Build Environment in the Projects pane.

QT5: Failed to load psql driver in windows

Most likely it's failing to dynamically link the qsqlpsql.dll file when it invokes LoadLibrary on it after your program requests that driver. LoadLibrary returns the same error code for when the target DLL is missing as for when one of the DLLs the target DLL depends on is missing or cannot be loaded. So Qt quite possibly gets a "library not found" error and assumes "oh, the Pg driver must not be in this Qt build", where in fact it's present and failing to load due to dependency issues, library compatibility problems, etc.

To determine why it's failing to load, you can as Frank Osterfeld suggested use a tool like Dependency Walker (depends.exe). If you're compiling 32-bit code on a 64-bit machine you want to get the 32-bit dependency walker.

It's quite likely to be failing because there's a dependency of qsqlpsql.dll missing - either libpq.dll, or one of the libraries that libpq build requires. Dependency walker will help isolate this. It's also possible you're trying to load a 64-bit libpq.dll in a 32-bit program, or vice versa.

You may also find it informative to run your program with Process Monitor tracing it. This will produce a lot of detail about which files it attempts to open / examine, among other things, and can help track down things like unexpected PATH issues.

If you're still stuck, there's always the option of stepping through with a debugger.



Related Topics



Leave a reply



Submit