Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PostgreSQL and Trying to connect using Qt

PostgreSQL and Trying to connect using Qt

Scheduled Pinned Locked Moved General and Desktop
46 Posts 8 Posters 39.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nHx4U
    wrote on 5 Nov 2013, 16:42 last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on 5 Nov 2013, 17:08 last edited by
      #2

      Hi,

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

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nHx4U
        wrote on 5 Nov 2013, 21:30 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Nov 2013, 22:04 last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nHx4U
            wrote on 5 Nov 2013, 22:23 last edited by
            #5

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

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 5 Nov 2013, 22:35 last edited by
              #6

              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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nHx4U
                wrote on 6 Nov 2013, 17:10 last edited by
                #7

                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.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mcosta
                  wrote on 6 Nov 2013, 18:43 last edited by
                  #8

                  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.

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nHx4U
                    wrote on 6 Nov 2013, 21:48 last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • VinorcolaV Offline
                      VinorcolaV Offline
                      Vinorcola
                      wrote on 6 Dec 2013, 09:40 last edited by
                      #10

                      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).

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        nHx4U
                        wrote on 14 Dec 2013, 18:15 last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          aftertaf
                          wrote on 6 Feb 2014, 23:09 last edited by
                          #12

                          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 . . . )

                          1 Reply Last reply
                          0
                          • N Offline
                            N Offline
                            nHx4U
                            wrote on 7 Feb 2014, 03:57 last edited by
                            #13

                            Hi aftertaf:

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

                            1 Reply Last reply
                            0
                            • TheBadgerT Offline
                              TheBadgerT Offline
                              TheBadger
                              wrote on 7 Feb 2014, 06:31 last edited by
                              #14

                              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.


                              Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

                              1 Reply Last reply
                              0
                              • C Offline
                                C Offline
                                clochydd
                                wrote on 7 Feb 2014, 15:11 last edited by
                                #15

                                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!

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  aftertaf
                                  wrote on 7 Feb 2014, 15:43 last edited by
                                  #16

                                  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...

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    aftertaf
                                    wrote on 7 Feb 2014, 18:22 last edited by
                                    #17

                                    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.... ?

                                    1 Reply Last reply
                                    0
                                    • C Offline
                                      C Offline
                                      clochydd
                                      wrote on 7 Feb 2014, 19:07 last edited by
                                      #18

                                      @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

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        aftertaf
                                        wrote on 7 Feb 2014, 19:11 last edited by
                                        #19

                                        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...:@

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          aftertaf
                                          wrote on 7 Feb 2014, 19:27 last edited by
                                          #20

                                          [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 :)

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved