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
Std::Ostringstream Printing the Address of the C-String Instead of Its Content
C++ Function Callbacks: Cannot Convert from a Member Function to a Function Signature
Compiling with G++ Using Multiple Cores
How to Get a "Codesigned" Gdb on Osx
Libraries in /Usr/Local/Lib Not Found
Which C++ Signals/Slots Library Should I Choose
How to Make a Heterogeneous Boost::Map
Extra Qualification Error in C++
How to Write Portable Code in C++
What Is an Iterator in General
Unresolved Externals in C++ When Using Vectors and Find
Compiling a Simple Parser with Boost.Spirit
What Are Some Better Ways to Avoid the Do-While(0); Hack in C++
Why Does a C/C++ Compiler Need Know the Size of an Array at Compile Time
Thread Safe Lazy Construction of a Singleton in C++
Copy a Streambuf's Contents to a String
What Is a Buffer Overflow and How to Cause One
What's the Difference Between the Win32 and _Win32 Defines in C++