Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10
QtWS25 Last Chance

Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10

Scheduled Pinned Locked Moved Solved Installation and Deployment
17 Posts 3 Posters 3.9k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Hi,

    What likely happened is that you had the 32bit command line activated.

    Your approach is the correct one: have all dependencies of the right architecture.

    That said, once you have the librairies, the fact that the database itself runs in 32 or 64bit should not be relevant.

    One additional thing that you might want to consider is to use an out of source build so you can build as many variation as you want without filling the sources with build artifacts.

    You're on the right track !

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

    L 1 Reply Last reply
    2
    • SGaistS SGaist

      Hi,

      What likely happened is that you had the 32bit command line activated.

      Your approach is the correct one: have all dependencies of the right architecture.

      That said, once you have the librairies, the fact that the database itself runs in 32 or 64bit should not be relevant.

      One additional thing that you might want to consider is to use an out of source build so you can build as many variation as you want without filling the sources with build artifacts.

      You're on the right track !

      L Offline
      L Offline
      Laplace
      wrote on last edited by
      #5

      @SGaist said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:

      That said, once you have the librairies, the fact that the database itself runs in 32 or 64bit should not be relevant.

      What do you mean by this? What kind of mixing and matching can I do? For example, can I use PostreSQL 12 (only comes in 64bit) for a Qt application that I build as 32bit?

      One additional thing that you might want to consider is to use an out of source build so you can build as many variation as you want without filling the sources with build artifacts.

      Does this mean somehow specifying "build the plugin and put it in XYZ folder" (as opposed to putting it in C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers or something like that)?

      Thanks!

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #6

        The server itself could be on a remote machine under a different OS. The client being in 64 or 32 does not have a role. As you noted, it's the client library that you need to build the plugin that needs to match the architecture of your application.

        Out of source build means literally that, you trigger the build from a folder outside of the sources. But the steps are the same.

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

        L 1 Reply Last reply
        1
        • SGaistS SGaist

          The server itself could be on a remote machine under a different OS. The client being in 64 or 32 does not have a role. As you noted, it's the client library that you need to build the plugin that needs to match the architecture of your application.

          Out of source build means literally that, you trigger the build from a folder outside of the sources. But the steps are the same.

          L Offline
          L Offline
          Laplace
          wrote on last edited by
          #7

          @SGaist said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:

          The server itself could be on a remote machine under a different OS. The client being in 64 or 32 does not have a role. As you noted, it's the client library that you need to build the plugin that needs to match the architecture of your application.

          The server vs. client part makes sense. What is not clear to me is: can I compile 32bit Qt drivers for PostgreSQL 12 (which is 64bit only)? Since the drivers are compiled from the PostgreSQL source and not the binaries, that should be possible, right?

          Thanks!

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Laplace
            wrote on last edited by Laplace
            #8

            I'm sorry to say I am still having trouble. The compiling the drivers is now fine, but I am having trouble when it comes to actually using them.

            From my applications log:

             QFactoryLoader::QFactoryLoader() looking at "C:/Qt/5.15.0/msvc2019_64/plugins/sqldrivers/qsqlpsqld.dll"
             Found metadata in lib C:/Qt/5.15.0/msvc2019_64/plugins/sqldrivers/qsqlpsqld.dll, metadata=
             {
                 "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
                 "MetaData": {
                     "Keys": [
                         "QPSQL7",
                         "QPSQL"
                     ]
                 },
                 "archreq": 1,
                 "className": "QPSQLDriverPlugin",
                 "debug": true,
                 "version": 331520
             }
             
             
             Got keys from plugin meta data ("QPSQL7", "QPSQL")
            

            So this is the actual debug plugin. The metadata looks good.

             Module loaded: C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers\qsqlpsqld.dll
            

            So it was able to load the DLL for the plugin...

             Cannot load library C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers\qsqlpsqld.dll: The specified module could not be found.
            

            But then failed to load it!

            It seems that some deps of qsqlpsqld.dll is failing to load. I checked dependency walker (this rewrite specifically) and LIBPQ.dll was missing. This DLL is located in C:\Program Files\PostgreSQL\12\lib which should have been included (or linked?) when building the plugin!

            After copying LIBPQ.dll to the plugin folder, the following were missing:

            libcrypto-1_1-x64.dll
            libssl-1_1-x64.dll
            libintl-8.dll
            WS2_32.dll
            WLDAP32.dll
            

            The first two are from OpenSSL, the last two are from Windows and finally libintl-8.dll seems to be from PostgreSQL itself.

            Here is the nmake log (here).

            I installed OpenSSL (using this installer). Installing this and fixed those two dependencies.

            I'm assuming WS2_32.dll and WLDAP32.dll are not causing the issue.

            So I'm stuck at libintl-8.dll: this is a PostreSQL lib, but in C:\Program Files\PostgreSQL\12\lib all I have is libintl.lib. My understanding of these things is limited, but I believe that libintl.lib is a static library, so wouldn't the compilation process of the plugin need to generate the above referenced DLL (libintl-8.dll)? Or where is the reference to libintl-8.dll coming from?

            Is there a way to avoid this hassle altogether by telling qmake or namke "just build/copy all of the required dependencies to C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers when you build"?

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @Laplace said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:

              "just build/copy all of the required dependencies to C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers when you build"?

              No, you have to take care for your deps by yourself with e.g. Dependency Walker.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              L 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @Laplace said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:

                "just build/copy all of the required dependencies to C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers when you build"?

                No, you have to take care for your deps by yourself with e.g. Dependency Walker.

                L Offline
                L Offline
                Laplace
                wrote on last edited by
                #10

                @Christian-Ehrlicher said in [Installing PostgreSQL on Qt 5.15/PostgreSQL

                No, you have to take care for your deps by yourself with e.g. Dependency Walker.

                Good to know at least that I am doing things the right way!

                I was able to find libintl-8.dll in C:\Program Files\PostgreSQL\12\bin.

                Still unable to load the plugin. It seems that WS2_32.dll and WLDAP32.dll are causing issues. These are Windows libraries. Googling reveals pretty generic results. If anyone has any ideas, I'd appreciate the input.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  I would check if the correct msvc runtime is installed on the target pc. Afair it needs the ones from msvc2015. But don't remember exactly.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Laplace
                    wrote on last edited by Laplace
                    #12

                    I was able to resolve things!

                    Here were the required dependencies:

                    • libcrypto-1_1-x64.dll: from OpenSSL install.
                    • libssl-1_1-x64.dll: from OpenSSL install.
                    • libpq.dll: from C:\Program Files\PostgreSQL\12\lib
                    • libintl-8.dll: from C:\Program Files\PostgreSQL\12\bin
                    • libiconv-2.dll: from C:\Program Files\PostgreSQL\12\bin

                    I first copied them manually to the same folder as my .exe, along with the actual plugin DLLs (qsqlpsql.dll). That worked.

                    Next I tried using windqtdeploy. It actually was able to detect all of them, but it copied them to a folder called sqldrivers which is a subdirectory of the folder my .exe is in. That did not work. I had to manually copy the following from the sqldrivers subdirectory to the main directory:

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

                    Is there any way to tell windqtdeploy to copy these DLLs to the .exe folder instead of the subfolder, hence avoiding one more manual step?

                    1 Reply Last reply
                    1
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @Laplace said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:

                      Is there any way to tell windqtdeploy to copy these DLLs to the .exe folder instead of the subfolder

                      No but they should be in the same dir as the plugin so it's strange - maybe you have some of those libs (with other version) in your PATH?

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      L 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @Laplace said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:

                        Is there any way to tell windqtdeploy to copy these DLLs to the .exe folder instead of the subfolder

                        No but they should be in the same dir as the plugin so it's strange - maybe you have some of those libs (with other version) in your PATH?

                        L Offline
                        L Offline
                        Laplace
                        wrote on last edited by
                        #14

                        @Christian-Ehrlicher said in [Installing PostgreSQL on Qt 5.15/PostgreSQL

                        No but they should be in the same dir as the plugin so it's strange - maybe you have some of those libs (with other version) in your PATH?

                        I don't think so because (1) I checked my PATH and didn't see anything and (2) I don't have any other versions of PostgreSQL intalled or anything like that.

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • L Laplace

                          @Christian-Ehrlicher said in [Installing PostgreSQL on Qt 5.15/PostgreSQL

                          No but they should be in the same dir as the plugin so it's strange - maybe you have some of those libs (with other version) in your PATH?

                          I don't think so because (1) I checked my PATH and didn't see anything and (2) I don't have any other versions of PostgreSQL intalled or anything like that.

                          Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          @Laplace Ok, then I'll accept it the way it is - no time to look further why it doesn't work like it should :)

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            Laplace
                            wrote on last edited by
                            #16

                            Alternatively: can I add the sqldrivers folder to the top of the current session (or whatever these are called in Window's)? So something equivalent to:

                            set "PATH=%cd%\sqldrivers;%PATH%"
                            myapp.exe
                            

                            But done automatically when double clicking the .exe.

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              Laplace
                              wrote on last edited by
                              #17

                              This did the trick:

                              #ifdef Q_OS_WIN
                                  // Add the sqldrivers folder to path
                                  QDir app_dir(QApplication::applicationDirPath());
                                  QString path;
                                  path = app_dir.absolutePath();
                                  path = path + "/sqldrivers";
                                  path = QStringLiteral("%1;%2").arg(path).arg(QString(qgetenv("PATH")));
                                  qputenv("PATH", path.toUtf8());
                              #endif
                              
                              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