Important: Please read the Qt Code of Conduct -

QPSQL driver - Postgresql 9 & Windows 7

  • After getting a new PC I didn't backup the PSQL driver I managed to compile with a lot of heartache, and now I have to it again. Since the instructions are practically non existent for my setup (which I would have thought is very common), and there are numerous posts on the Internet with people trying to get it to work, each one trying something different, I'll try to get some help here, and if resolved maybe make a wiki out of it to solve the confusion.

    My environment is like this:

    • Windows 7 64 bit
    • PostgreSQL 9 64 bit [prepackaged and downloaded from EnterpriseDB] (installed locally)
    • QtCreator 2.1 (using minigw32)
    • Qt 4.7.2 [pre-built versions from].

    PostgreSQL is installed at C:\PSQL
    Qt is installed at C:\Qt\4.7.2

    My actions have been as follows:

    1. Add C:\PSQL\bin to the system path

    As I need to convert the libpq.lib to a format that can be used by mingw32:

    1. Downloaded the mingw-utils package and copied reimp.exe to C:\Qt\4.7.2\bin
    2. CD C:\PSQL\lib
    3. REIMP -d libpq.lib (this creates a file libpq.def)
    4. DLLTOOL --input-def libpq.def -dllname libpq.dll --output-lib libpq.a -k (this creates a file libpq.a)
    5. CD C:\Qt\4.7.2\src\plugins\sqldrivers\psql
    6. qmake "INCLUDEPATH+=C:\PSQL\include" "LIBS+=C:\PSQL\lib\libpq.a"
    7. mingw32-make debug
    8. mingw32-make release

    The compilation gives some warnings
    ......\sql\drivers\psql\qsql_psql.cpp: In member function 'virtual QSqlIndex QPSQLDriver::primaryIndex(const QString&) const':
    ......\sql\drivers\psql\qsql_psql.cpp:979: warning: enumeration value 'VersionUnknown' not handled in switch
    ......\sql\drivers\psql\qsql_psql.cpp: In member function 'virtual QSqlRecord QPSQLDriver::record(const QString&) const':
    ......\sql\drivers\psql\qsql_psql.cpp:1056: warning: enumeration value 'VersionUnknown' not handled in switch
    but they seem harmless to me, as the DLLs are generated ok (libqsqlpsqld4.a & qsqlpsqld4.dll in the debug folder, and libqsqlpsql4.a & qsqlpsql4.dll in the release folder).

    At this stage, I also delete anything related to qsqlpsql in the QtPluginCache in the registry (HKCU\Software\Trolltech\OrganizationDefaults..).

    Copying them to C:\Qt\4.7.2\plugins\sqldrivers, I get a driver not loaded when trying to use it (my application has another QODBC connection that works fine).
    If I use
    qputenv("QT_DEBUG_PLUGINS", QByteArray("1")
    in my code,
    I get in the debug output:
    QFactoryLoader::QFactoryLoader() looking at "C:/Qt/4.7.2/plugins/sqldrivers/qsqlpsqld4.dll"
    "Cannot load library C:/Qt/4.7.2/plugins/sqldrivers/qsqlpsqld4.dll: "
    could not load

    I open the dll with dependencywalker.exe and I get the following in the log:
    @Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
    Error: Modules with different CPU types were found.
    Warning: At least one delay-load dependency module was not found.
    Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.@
    Looking at the modules:

    • It cannot find one dll (IESHIMS.DLL)
    • on all non-Qt DLLs x64 (under CPU) is shown in red
    • the link checksum of QTCORE4.DLL is in red

    These don't seem serious enough to me, and to be sure, I open QSQLODBC4.DLL with dependencywalker.exe, because I know it's working:

    • I get the exact errors in the log and information in the modules (the cpu red, and red linkage on qtcore).

    Can someone please help?

  • Is it possible that it could be a 32/64 bit issue?
    I noticed that the QSQLPSQL4.dll is 32 bit, but links to LIBPQ.DLL which is 64 bit (and some other system 64 bit dlls), and QTSQL4+QTCORE4+LIBGCC_S_DW2-1 which are 32 bit.

    On the other hand, the same seems to be true for QSQLODBC4 (it's 32 bit, linked to ODBC32 (which is strangely a 64bit DLL), and the rest like QSQLPSQL...

  • I seem to be getting somewhere...
    It's definitely some mess with the 64 bit version of Postgresql.

    • downloaded and installed the 32 bit version in a folder named C:\PSQL32

    • changed the PATH variable to C:\PSQL32\BIN

    • repeated the exact procedure as above (but using C:\PSQL32\lib) and everything worked like a charm.

    -> This PSQL driver can connect to both the 32 bit server and the 64 bit server

    -> I tried to be clever and remove the 32 bit version and change the PATH to C:\PSQL\BIN (the 64 bit), but it didn't work.

    So it doesn't like Qt can compile or use the 64 bit library that comes with the prepackaged 64 bit Postgresql...

  • I think you can link against the 64 bit version, but you need to use a 64 bit version of Qt and a 64 bit toolchain for that. I did the same for MySql once, and that worked.

  • That would mean building Qt, right?
    I don't see a pre-packaged Qt SDK for Windows 64 available.

  • Yes that is correct. You will need to build Qt. It's easy to do though.

  • I've managed to avoid it so far, so it make me nervous [plus I don't know where to start, but google is your friend] :)

    I'm guessing I'll be able to build both 32 bit and 64 bit executables from this build, or do I need to hold on to my existing SDK for 32 bit?

  • I think you would be best to build the 64-bit version of Qt in a new directory. That way you can keep your existing 32-bit install working. They can live perfectly happy side by side. So in the end you coudl have dirs like this:


    or whatever you choose to name the directories as. Then to build against one or the other just be sure to use the corresponding version of qmake form within the appropriate directory.

    There should be plenty of docs on how to configure and build Qt on Windows both in the official Qt docs and on devnet.

  • 've solved the problem, I'm in the same.

  • GCC 32bit requires 32bit postgres.

  • You will need to compile the drivers, then you will get into plugin Qt dir the files and or qsqlpsql4.dll if windows, then the files, and sould go to your lib folder ex(/usr/lib).

  • mingw compile postgres with fixed and so the driver can generate.

  • I have x32 postgres 9.2
    I try make QPSQL driver, and receive this error. ????

    @C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\psql>qmake -o Makefile "INCLUDEP
    ATH+=C:\PostgreSQL\9.2\include" "LIBS+=C:\PostgreSQL\9.2\lib\libpq.a" psq
    Qt: Untested Windows version 6.2 detected!

    make -f Makefile.Debug
    make[1]: Entering directory C:/QtSDK/QtSources/4.8.1/src/plugins/sqldrivers/psq l' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT - DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB - DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_TH READ_SUPPORT -I"c:\QtSDK\Symbian\SDKs\Symbian1Qt473\include\QtCore" -I"c:\QtSDK\ Symbian\SDKs\Symbian1Qt473\include\QtSql" -I"c:\QtSDK\Symbian\SDKs\Symbian1Qt473 \include" -I"c:\PostgreSQL\9.2\include" -I"c:\Program" -I"Files\PostgreSQL\9.2\i nclude" -I"c:\QtSDK\Symbian\SDKs\Symbian1Qt473\include\ActiveQt" -I"debug" -I"c: \QtSDK\Symbian\SDKs\Symbian1Qt473\mkspecs\default" -o debug\main.o main.cpp g++: CreateProcess: No such file or directory make[1]: *** [debug/main.o] Error 1 make[1]: Leaving directoryC:/QtSDK/QtSources/4.8.1/src/plugins/sqldrivers/psql
    make: *** [debug] Error 2@

  • after i run C:[Qt dir]\Src\qtbase\src\plugins\sqldrivers\psql>mingw32-make

    i get this error:

    mingw32-make -f Makefile.Release all
    mingw32-make[1]: Entering directory 'C:/Qt/Qt5.0.2/5.0.2/Src/qtbase/src/plugins/
    g++ -c -pipe -fno-keep-inline-dllexport -O2 -std=c++0x -fno-exceptions -frtti -W
    I"files\postgresql\9.2\include" -I"C:\Qt\Qt5.0.2\5.0.2\mingw47_32\include" -I"C:
    \Qt\Qt5.0.2\5.0.2\mingw47_32\include\QtSql" -I"C:\Qt\Qt5.0.2\5.0.2\mingw47_32\in
    clude\QtSql\5.0.2" -I"C:\Qt\Qt5.0.2\5.0.2\mingw47_32\include\QtSql\5.0.2\QtSql"
    -I"C:\Qt\Qt5.0.2\5.0.2\mingw47_32\include\QtCore" -I".moc\release_shared" -I"..
    ......\mkspecs\win32-g++" -o .obj\release_shared\qsql_psql.o ......\sql\driv
    ......\sql\drivers\psql\qsql_psql.cpp:58:22: fatal error: libpq-fe.h: No such
    file or directory
    compilation terminated.
    Makefile.Release:483: recipe for target '.obj/release_shared/qsql_psql.o' failed

    mingw32-make[1]: *** [.obj/release_shared/qsql_psql.o] Error 1
    mingw32-make[1]: Leaving directory 'C:/Qt/Qt5.0.2/5.0.2/Src/qtbase/src/plugins/s
    makefile:38: recipe for target 'release-all' failed
    mingw32-make: *** [release-all] Error 2

    any idea how to get over? the QPSQL driver is not loaded yet.

  • [quote author="angelicaP" date="1370121154"]
    any idea how to get over? the QPSQL driver is not loaded yet. [/quote]

    Any luck solving the problem?

  • [quote author="angelicaP" date="1370121154"]
    any idea how to get over? the QPSQL driver is not loaded yet. [/quote]

    Any luck solving the problem?

Log in to reply