PostgreSQL and Trying to connect using Qt



  • I know this has been discussed many times in the forums. I've tried many of the examples and still can't get Qt to connect with PostgreSQL. (I'm an extreme beginner in C++ and Qt, I've only been able to complete one very simple tutorial example - with the forum's help. Please have some mercy in helping me solve this one.

    I’ve downloaded and installed: Qt 5.1.1 with mingw48-32 to desktop PC running Windows 7 ×64
    Trying to connect to PostgeSQL 9.2 Database. Connects and runs with pgAdmin III, dbVizualizer, and Valentina Studio. Qt won’t recognize PSQL.

    (from Qt Documentation and Forum). Code and Messages below. Appreciate your help.


    How to Build the QPSQL Plugin on Windows

    Install the appropriate PostgreSQL developer libraries for your compiler. Assuming that PostgreSQL was installed in C:\psql, build the plugin as follows:
    cd %QTDIR%\src\plugins\sqldrivers\psql
    qmake "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
    nmake
    Users of MinGW may wish to consult the following online document: PostgreSQL MinGW/Native Windows.
    Note: This database plugin is not supported for Windows CE.


    My actual code and paths:

    cd C:\Qt\Qt5.1.1\5.1.1\Src\qtbase\src\plugins\sqldrivers\psql
    qmake -o Makefile INCLUDEPATH+="C:\PostgreSQL\9.2\include" "LIBS+=C:\PostgreSQL\9.2\lib\libpq.lib" psql.pro
    mingw32-make

    I’m assuming the above is entered from the command prompt – or is it coded in the .pro file? There is a training video (ICS, I think?) showing how to connect with SQL Server Express. It does not mention this, or anything else, other than the simple .PRO and .CPP files. It of course works properly with the simple code – no use of Dependency Walker, copies of dlls., or creating a Release file. It just works!
    What does the qmake line actually make? And where?
    What does the psql,pro do? What does the final mingw32-make?
    It also appears that the Qt location for psql occurs in 2 locations/directories with Qt. Did I choose the right one?


    PSQL.PRO

    QT += core
    QT += sql
    QT += gui

    TARGET = PSQL_TEMP
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    MAIN.CPP

    #include <QCoreApplication>
    #include <QSqlDatabase>
    #include <QtSql>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
            db.setHostName("localhost");
            db.setDatabaseName("pg_nhx");
            db.setUserName("postgres");
            db.setPassword("postgres");
            db.open();
    
           // db.close();
    
    return a.exec&#40;&#41;;
    

    OUTPUT MESSAGES

    22:19:19: Running steps for project PSQL_TEMP...
    22:19:19: Configuration unchanged, skipping qmake step.
    22:19:19: Starting: "C:\Qt\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe"
    C:/Qt/Qt5.1.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory 'C:/Users/Steve/Desktop/build-PSQL_TEMP-Desktop_Qt_5_1_1_MinGW_32bit-Debug'
    mingw32-make[1]: Nothing to be done for 'first'.
    mingw32-make[1]: Leaving directory 'C:/Users/Steve/Desktop/build-PSQL_TEMP-Desktop_Qt_5_1_1_MinGW_32bit-Debug'
    22:19:19: The process "C:\Qt\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe" exited normally.
    22:19:19: Elapsed time: 00:00.

    Output in Command /Console Window

    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7



  • Hi,

    you MUST ensure that the libpq.dll is in your PATH.



  • Hi. Thanks for the quick reply. libpq.dll is in the PATH. Still get same result. Any other suggestions? Any one else out there willing to offer a possible solution.? I need all the help I can get. Thanks.


  • Lifetime Qt Champion

    Hi,

    Check also whether libpq.dll has other dependencies not in PATH



  • " Check also whether libpq.dll has other dependencies not in PATH"

    I don't know what this means - or how to check.


  • Lifetime Qt Champion

    libpq.dll is a dependency of Qt's psql plugin. But this dll might also depend on others. You can use Dependency Walker to check what are the dlls needed by libqp.dll



  • Well, I used Dependency Walker on LIBPQ.DLL in the Qt......plugins\sqldrivers\ folder. no dependencies showed up????

    Now what can I do?

    Thanks again.



  • Hi,

    you should check dependencies of libpq.dll installed with PostgreSQL.
    Remenber that in Windows to load a DLL, it must be in the PATH.



  • Perhaps I don't know what I'm looking at in Dependency Walker. The yellow errors refer to files that are not even on my machine! I've attached a listing of the results. My PATH statement (in Windows Environment) now includes references to almost every Postgres and Qt directory on my drive.

    API-MS-WIN-CORE-COM-L1-1-0.DLL
    API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
    API-MS-WIN-CORE-WINRT-L1-1-0.DLL
    API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
    API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
    API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL

    DCOMP.DLL
    IESHIMS.DLL

    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.

    I'm sure you can help. I'm just getting really frustrated about this!

    Thanks.



  • I've just got the same problem. When a driver is available but not loaded, it means there is a DLL missing. To solve that, you must have:

    In Production:
    In the same directory than your exe, you must have the libeay32.dll and the libpq.dll (You'll find them in the bin directory of postgres) and in the sqldrivers sub-directory, you must have qsqlpsql.dll.

    In development:
    In your build directory, you must put the libeay32.dll and the libpq.dll (in the same level than the Makefiles if you keep the default configuration).

    This is for Windows 32bits (I can't realy tell for 64bits).



  • Thanks for your help.

    I've tried your suggestion but still doesn't work.

    I have Win7 x64. Maybe that's the problem.

    Any other suggestions? I'll keep trying. Appreciate it.



  • I have the same problem, and same (absence of) experience with C++/QT.

    I've tried all the google search results under the sun and no go either.
    If you found anything, please say so :)

    I'll post relevant stuff tomorrow on my exact issue (cos tonight the laptop is close to being thrown across the room . . . )



  • Hi aftertaf:

    Nope! Still working on it. Appreciate your mutual frustration.
    Hopefully, one of us will resolve the issue >>>>> SOON!



  • HI,

    A quick check to see if it is a missing or unfound dll is to copy all of the content in the PostgreSQL lib folder into the folder of your exe. I know this is not the best solution, but you can sift out the ones not needed afterwards if you at least get it to work.
    From my experience the following dlls are needed:

    • libeay32.dll
    • libiconv-2.dll
    • libintl-8.dll
    • libpq.dll
    • ssleay32.dll

    I am not sure if it can be that the plugin is build for debug or release.

    You are correct, the build command should be called from the command line:
    @

    mingw32-make
    mingw32-make RELEASE
    @

    and then to install:

    @

    mingw32-make debug-install
    mingw32-make release-install
    @

    The x64 should not be a problem if you use 32-bit PostgreSQL libs with 32-bit compile/Qt.



  • Hi nHx4U, I work with PostgreSQL and Qt5,2 on Unix and Win7 64.
    On Win7 I installed PSQL 32 and Qt 5.2 with mingw32. After setting up a 2nd Win7 machine I had similar problems as you have now.
    Firstly they had been caused by an old PSQL 64 install, which had not completely been removed.
    When removed and restarted, I still encountered the "QSqlDatabase: QPSQL driver not loaded" problem. After deleting all entries in the Application Build directory (Debug/Release) and building the project it works fine!



  • currently following this tuto:
    http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW

    I changed the powershell script to make it use QT 5.2.1, and for it to build some odbc & psql drivers (i think)

    Get the Powershell script from there, read the tuto fully and do what is says, fully.......

    I've changed these lines:
    @78: $QtSrcUrl = "http://download.qt-project.org/official_releases/qt/5.2/5.2.1/single/qt-everywhere-opensource-src-5.2.1.7z",
    169: -make libs -nomake tools -nomake examples -nomake tests -plugin-sql-odbc -plugin-sql-psql"@

    I'll let you know about the outcome.
    Anyone figures out what I'm doing and cares to give a pointer on how to get it working (tm) from my actions so far, or to correct me :), feel free...



  • i have :
    c:\Qt with the binary installer version
    c:\Qt\Static with the 'still compiling' static version (with the psql stuff I hope!!)

    c:\PgSQl93_x86 with postgres 32bit & headers, libs, the whole installer package

    Also have postgres 9.1 64bit (used for work).

    Can someone, somewhere, write a step by step tutorial on how do to it, what prerequisites are what, which differences need which slightly different approach.... ?



  • @aftertaf
    Here's a short tutorial for Qt + PSQL:

    1. Install Qt 5.2 32 from binary mingw32 "Qt 5.2.1 for Windows 32-bit (MinGW 4.8, OpenGL, 634 MB)"
    2. Install Qt 5.2 Sorces
    3. Install PostgreSQL 32-bit
    4. Compile the QPSQL plugin

    REM:
    a. Check the PATH (mingw and postgresql\bin and lib)
    b. I could not manage to have both PSQL 32 and 64 working together on one Win7 - only the 32-Bit works and it only worked after completely uninstalling PSQL 64 and build my own Qt-Applications completely new in a clean directory!

    Hope this is useful for you



  • grrrrrrrrrrr

    @xcopy /s /q /y /i C:\Qt\Static\src\qt-everywhere-opensource-src-5.2.1\qtbase\mks
    pecs\winphone-arm-msvc2012 C:\Qt\Static\5.2.1\mkspecs\winphone-arm-msvc2012
    2 File(s) copied
    xcopy /s /q /y /i C:\Qt\Static\src\qt-everywhere-opensource-src-5.2.1\qtbase\mks
    pecs\winphone-x86-msvc2012 C:\Qt\Static\5.2.1\mkspecs\winphone-x86-msvc2012
    2 File(s) copied
    xcopy /s /q /y /i C:\Qt\Static\src\qt-everywhere-opensource-src-5.2.1\qtbase\mks
    pecs\winrt-arm-msvc2012 C:\Qt\Static\5.2.1\mkspecs\winrt-arm-msvc2012
    2 File(s) copied
    xcopy /s /q /y /i C:\Qt\Static\src\qt-everywhere-opensource-src-5.2.1\qtbase\mks
    pecs\winrt-x64-msvc2012 C:\Qt\Static\5.2.1\mkspecs\winrt-x64-msvc2012
    2 File(s) copied
    xcopy /s /q /y /i C:\Qt\Static\src\qt-everywhere-opensource-src-5.2.1\qtbase\mks
    pecs\winrt-x86-msvc2012 C:\Qt\Static\5.2.1\mkspecs\winrt-x86-msvc2012
    2 File(s) copied
    xcopy /s /q /y /i C:\Qt\Static\src\qt-everywhere-opensource-src-5.2.1\qtbase\doc
    \global C:\Qt\Static\5.2.1\doc\global
    58 File(s) copied
    mingw32-make[1]: Target 'install' not remade because of errors.
    mingw32-make[1]: Leaving directory 'C:/Qt/Static/src/qt-everywhere-opensource-sr
    c-5.2.1/qtbase'
    makefile:72: recipe for target 'module-qtbase-install_subtargets' failed
    mingw32-make: *** [module-qtbase-install_subtargets] Error 2
    mingw32-make: Target 'install' not remade because of errors.
    Press Enter to continue...:@



  • [quote author="clochydd" date="1391800040"]aftertaf
    Here's a short tutorial for Qt + PSQL:

    1. Install Qt 5.2 32 from binary mingw32 "Qt 5.2.1 for Windows 32-bit (MinGW 4.8, OpenGL, 634 MB)"
    2. Install Qt 5.2 Sorces [/quote]
      -> during install of 'binary' in step above?,
      -> as a tarball just uninflated somewhere 'clean'?
      [quote]3. Install PostgreSQL 32-bit [/quote]
      ->ok, i'll switch now and completely purge x64 9.1 +9.3 from this system

    [quote]4. Compile the QPSQL plugin [/quote]
    @
    include <n00b.h>
    #IFNDEF compile, what do i do?
    @
    i.e. us n00bs, even if we've compiled kernels and broken our teeth on linux, we know how to speak PC in a broad sense, but this is a bit like reading 'the matrix' for us, and we ARE trying....

    I've tried like 50 times to follow the QODBC & QPSQL stuff via google and qt project docs, and something (different every time) ain't working, and my n00bness combined with the fact i'm gutting my system of QT binary & source over and over means i dont understand and can't remember the errors i'm having.
    I've been trying for the past 2 weeks in silence and solitude before bleeding out here...

    [quote]REM:
    a. Check the PATH (mingw and postgresql\bin and lib) [/quote]
    ->the SET PATH env variable , to be sure they're both in there for the system and for the cmd prompts i've been launching??
    Yep.

    [quote]b. I could not manage to have both PSQL 32 and 64 working together on one Win7 - only the 32-Bit works and it only worked after completely uninstalling PSQL 64 and build my own Qt-Applications completely new in a clean directory! [/quote]
    OK, cleaning up (again), this time PGx64 too

    [quote]Hope this is useful for you [/quote]
    me too, will let you know :)



  • @aftertaf: I have modified my tutorial so that now you will see all steps from downloading to building the plugins.
    This is what I've done to make Qt 32-bit and PSQL 32-bit work on Win7 64-Bit:

    1. Prepare compiling of the plugin (Lets assume we install Qt + Sources to C:\Qt, PostgresSQL to C:\Programs(86x)):

    2. Download Qt 5.2.1 32-bit: http://download.qt-project.org/official_releases/qt/5.2/5.2.1/qt-opensource-windows-x86-mingw48_opengl-5.2.1.exe

    3. Run the .exe, install to C:\Qt\Qt5.2.1

    4. Download sources: http://download.qt-project.org/official_releases/qt/5.2/5.2.1/single/qt-everywhere-opensource-src-5.2.1.zip

    5. Extract zip to C:\Qt\Qt5.2.1

    6. Download PostGreSQL 32-bit: http://www.enterprisedb.com/postgresql-932-1-installers-win32?ls=Crossover&type=Crossover

    7. Modify PATH:
      set QTSDK_SQLDRIVERS_PATH=C:\Qt\Qt5.2.0\5.2.1\mingw48_32\plugins\sqldrivers
      set QT_SRC_PATH=C:\Qt\Qt5.2.1\5.2.1\Src\qtbase
      set POSTGRES32=C:\Progra~2\PostgreSQL\9.3 (USE Progra~2 FOR Programs(86x)!)

    8. cd %QT_SRC_PATH%\src\plugins\sqldrivers\psql

    9. add permanently to PATH (Control Panel): C:\Qt\Qt5.2.1\Tools\mingw48_32\bin

    10. modify C:\Progra~2\PostgreSQL\9.3\include\pthread.h (multiple definitions of struct timespec):
      replace: #ifndef HAVE_STRUCT_TIMESPEC
      with: #if ((!defined(_TIMESPEC_DEFINED)) && (!defined(HAVE_STRUCT_TIMESPEC)))

    11. start building the plugins:
      C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin\qmake "INCLUDEPATH+=%POSTGRES32%\include" "LIBS+=%POSTGRES32%\lib\libpq.lib" psql.pro
      mingw32-make debug
      mingw32-make release

    12. copy the newly created plugins to C:\Qt\Qt5.2.0\5.2.1\mingw48_32\plugins\sqldrivers:
      copy release\libqsqlpsql.a %QTSDK_SQLDRIVERS_PATH%
      copy release\qsqlpsql.dll %QTSDK_SQLDRIVERS_PATH%
      copy debug\libqsqlpsqld.a %QTSDK_SQLDRIVERS_PATH%
      copy debug\qsqlpsqld.dll %QTSDK_SQLDRIVERS_PATH%



  • 1: Thanks for taking time out :)
    2: OK, i've just reviewed and adapted to my environment slightly

    I get this error:
    @g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -fno-exceptions -frtti -Wall -Wextra -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1\QtCore" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore" -I".moc\debug" -I"........\mkspecs\win32-g++" -o .obj\debug\qsql_psql.o ......\sql\drivers\psql\qsql_psql.cpp
    ......\sql\drivers\psql\qsql_psql.cpp:59:22: fatal error: libpq-fe.h: No suchfile or directory
    #include <libpq-fe.h>
    ^
    compilation terminated.
    Makefile.Debug:497: recipe for target '.obj/debug/qsql_psql.o' failed
    mingw32-make[1]: *** [.obj/debug/qsql_psql.o] Error 1
    mingw32-make[1]: Leaving directory 'c:/QT/5.2.1/Src/qtbase/src/plugins/sqldrivers/psql'
    makefile:48: recipe for target 'debug' failed
    mingw32-make: *** [debug] Error 2@

    my path & env.vars set in the dos prompt:(which matches, i have triple checked)
    set QTSDK_SQLDRIVERS_PATH=C:\QT\5.2.1\mingw48_32\plugins\sqldrivers
    set QT_SRC_PATH=c:\QT\5.2.1\Src\qtbase
    set POSTGRES32=c:\psql93_x86

    C:\Qt\5.2.1\mingw48_32\bin;C:\Qt\Tools\mingw48_32\bin;C:\Qt\Tools\QtCreator\bin;C:\psql93_x86\bin;C:\psql93_x86\lib;C:\psql93_x86\include;C:\psql93_x86\include\libpq;C:\Perl\site\bin;C:\Perl\bin;C:\Windows;C:\Windows\system32;C:\Windows\System32\WindowsPowerShell\v1.0\C:\Windows\System32\Wbem;C:\trace;C:\trace\dll;c\trace\prod;C:\windev55;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE;C:\Program Files (x86)\Microsoft Application Virtualization Client;C:\Program Files\doxygen\bin



  • Forum post typo:
    i do have libpq-fe.h in c:\psql93_x86\include\ (not c:\pgsql93_x86\include)
    20.5k, dated 3rd Dec 2013



  • But c:\pgsql93_86\include\ is not in the maker's includepath
    See my suggestion item 11.:
    [11. start building the plugins:
    C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin\qmake “INCLUDEPATH+=%POSTGRES32%\include” “LIBS+=%POSTGRES32%\lib\libpq.lib” psql.pro]
    good luck!



  • that's what i'm doing, exactly...
    but still not finding it.


  • Lifetime Qt Champion

    And what if you replace %POSTGRES32% with the actual path BUT using forward slashes



  • result (again)
    @C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>C:\Qt\5.2.1\mingw48_32\bin\qmake "INCLUDEPATH+=c:/psql93_x86/include" "LIBS+=c:/psql93_x86/lib/libpq.lib" psql.pro

    C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>mingw32-make debug
    mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory 'C:/QT/5.2.1/Src/qtbase/src/plugins/sqldrivers/psql'
    g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -fno-exceptions -frtti -Wall -Wextra -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1\QtCore" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore" -I".moc\debug" -I"........\mkspecs\win32-g++" -o .obj\debug\qsql_psql.o ......\sql\drivers\psql\qsql_psql.cpp
    ......\sql\drivers\psql\qsql_psql.cpp:59:22: fatal error: libpq-fe.h: No such file or directory
    #include <libpq-fe.h>
    ^
    compilation terminated.
    Makefile.Debug:497: recipe for target '.obj/debug/qsql_psql.o' failed
    mingw32-make[1]: *** [.obj/debug/qsql_psql.o] Error 1
    mingw32-make[1]: Leaving directory 'C:/QT/5.2.1/Src/qtbase/src/plugins/sqldrivers/psql'
    makefile:48: recipe for target 'debug' failed
    mingw32-make: *** [debug] Error 2
    @

    Relevant env vars:(edited for readability)
    Path=
    C:\Qt\5.2.1\mingw48_32\bin;
    C:\Qt\Tools\mingw48_32\bin;
    C:\Qt\Tools\QtCreator\bin;
    C:\psql93_x86\bin;
    C:\psql93_x86\lib;
    C:\psql93_x86\include;
    C:\psql93_x86\include\libpq;
    C:\Perl\site\bin;
    C:\Perl\bin;
    C:\Windows;
    C:\Windows\system32;
    C:\Program Files\doxygen\bin
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.BPL;.lib
    POSTGRES32=c:\psql93_x86
    POSTGRES322=c:/psql93_x86
    QTSDK_DRIVERSPATH=C:\QT\5.2.1\mingw48_32\plugins\sqldrivers
    QTSDK_DRIVERSPATH2=C:/QT/5.2.1/mingw48_32/plugins/sqldrivers
    QT_SRC_PATH=C:\Qt\5.2.1\Src\qtbase
    QT_SRC_PATH2=C:/Qt/5.2.1/Src/qtbase



  • tried a different approach, still NOK.

    copied all of the c:\psql93_x86\include folder (+subdirs) into C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql (directory the make enters before the fail)

    it gets further before borking.
    @C:\Qt\5.2.1\mingw48_32\bin\moc.exe -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -D__GNUC__-DWIN32 -I. -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1\QtCore" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore" -I".moc\debug" -I"........\mkspecs\win32-g++" ......\sql\drivers\psql\qsql_psql_p.h -o .moc\debug\moc_qsql_psql_p.cpp
    g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -fno-exceptions -frtti -Wall -Wextra -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1\QtCore" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore" -I".moc\debug" -I"........\mkspecs\win32-g++" -o .obj\debug\moc_qsql_psql_p.o.moc\debug\moc_qsql_psql_p.cpp
    g++ -shared -Wl,--out-implib,C:\QT\5.2.1\Src\qtbase\plugins\sqldrivers\libqsqlpsqld.a -o ........\plugins\sqldrivers\qsqlpsqld.dll .obj/debug/main.o .obj/debug/qsql_psql.o .obj/debug/moc_qsql_psql_p.o -lpq -LC:\Qt\5.2.1\mingw48_32\lib -lQt5Sqld -lQt5Cored

    c:/qt/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lpq
    collect2.exe: error: ld returned 1 exit status
    Makefile.Debug:80: recipe for target '........\plugins\sqldrivers\qsqlpsqld.dll' failed
    mingw32-make[1]: *** [........\plugins\sqldrivers\qsqlpsqld.dll] Error 1
    mingw32-make[1]: Leaving directory 'C:/QT/5.2.1/Src/qtbase/src/plugins/sqldrivers/psql'
    makefile:48: recipe for target 'debug' failed
    mingw32-make: *** [debug] Error 2@
    i'm so close i can smell the SELECT*, but still no cigar



  • You are using mingw32's gcc to compile qt and trying to use postgreql library compiled with MSVC.

    MSVC uses .LIB for libraries while Mingw32 (gcc + binutils) uses .a or .so files for libraries.

    You can try either of the following methods: a. compile Qt using MSVC. b. use mingw32 to compile postgresql and use its libraries.
    From:
    http://stackoverflow.com/questions/5487236/building-qt-postgresql-driver

    anyone have an easy to follow 'how to build postgres from sources with mingw '?
    or easier still, how to "use" the "QT" ODBC driver instead?



  • ...
    just build libpq.a from sources . . . .
    http://pgolub.wordpress.com/2008/12/15/building-postgresql-client-library-using-mingw-under-winxp-sp3/

    don't know what to do with it.
    sorry for by n00bness, people...



  • It is not necessary to compile postgresql, I used the binaries 32-bit and with installing ./lib and ./include had been provided, too.
    Your make does not recognise the psql includes (the stuff, that follows -I) and that's why you still receive the message 'libpq-fe.h not found'.
    Do you see the same error if you use backslashed paths with you qmake command? Qt uses forward slashes but I had success with the backslashed command.


  • Lifetime Qt Champion

    Just to be sure, wouldn't by any chance libpq-fe.h be in include/libpq ? If so it's that last element that was missing.



  • Yes, this has been installed in "C:\Program Files (x86)\PostgreSQL\9.3\include" together with the binaries of PostgeSQL 32-bit:
    "03.12.2013 06:13 21.082 libpq-fe.h"
    and - the PostgreSQl include has to be added to qmake!


  • Lifetime Qt Champion

    Indeed, but you need to give the full path to libqp-fe.h not just the path that contains the libpq folder.

    Please avoid having spaces in your path when developing, it something that is not working very well on windows



  • on my system i installed postgreSQL x86 9.3 to c:\psql93_x86\

    so... the qmake command where i specify the INCLUDE+=, LIBS+= etc . . .
    i need to tell it precisely and exactly where libqp-fe.h is, including full path ?

    how do I do that, i.e. what separator do i use to add more than one entry into the "INCLUDE+=" that i've already specified (using clochydd's tuto on page 2. .) ?



  • Go to the Qt plugin source directory:
    cd QT_SRC_PATH\src\plugins\sqldrivers\psql

    Start building the plugins:
    (Change this to your mingw32 path: C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin)
    C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin\qmake “INCLUDEPATH+=c:\psql93_x86\include”
    “LIBS+=c:\psql93_x86\lib\libpq.lib” psql.pro


  • Lifetime Qt Champion

    libpq-fe.h being in include/libpq

    You should use

    @“INCLUDEPATH+=c:/psql93_x86/include/libpq”@



  • same :(



  • Don't give up - we will find a solution, hopefully!

    • Is the qmake error message concerning the libpq-fe.h exactly as before?
    • Could you please post the message again?
    • Could you post the directory list of c:\psql93_x86\include?


  • just tried making the odbc driver again...
    and get the Driver not Loaded message :)


    C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>c:\Qt\5.2.1\mingw48_32\bin\qm
    ake.exe "INCLUDEPATH+=c:/psql93_x86/include/libpq" "LIBS+=c:/psql93_x86/lib/libp
    q.lib" psql.pro

    C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>mingw32-make debug
    mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory 'C:/QT/5.2.1/Src/qtbase/src/plugins/sqldrive
    rs/psql'
    g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -fno-exceptions -frtti -Wa
    ll -Wextra -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEP
    TIONS -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -I"C:\Qt\5.2.1\mingw48_32\inclu
    de\QtSql\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql\5.2.1\QtSql" -I"C:\Qt\5.
    2.1\mingw48_32\include" -I"C:\Qt\5.2.1\mingw48_32\include\QtSql" -I"C:\Qt\5.2.1
    mingw48_32\include\QtCore\5.2.1" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore\5.2.1
    QtCore" -I"C:\Qt\5.2.1\mingw48_32\include\QtCore" -I".moc\debug" -I"........
    mkspecs\win32-g++" -o .obj\debug\qsql_psql.o ......\sql\drivers\psql\qsql_psql
    .cpp
    ......\sql\drivers\psql\qsql_psql.cpp:59:22: fatal error: libpq-fe.h: No such
    file or directory
    #include <libpq-fe.h>
    ^
    compilation terminated.
    Makefile.Debug:497: recipe for target '.obj/debug/qsql_psql.o' failed
    mingw32-make[1]: *** [.obj/debug/qsql_psql.o] Error 1
    mingw32-make[1]: Leaving directory 'C:/QT/5.2.1/Src/qtbase/src/plugins/sqldriver
    s/psql'
    makefile:48: recipe for target 'debug' failed
    mingw32-make: *** [debug] Error 2


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.