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. Adding PostgreSQL support
Forum Updated to NodeBB v4.3 + New Features

Adding PostgreSQL support

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 1.4k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    Slei
    wrote on 11 Feb 2019, 23:11 last edited by
    #1

    Hey,

    I'm currently having issues to get my old QT postgresql build working on a new pc.
    It was once working on my old one but I simply can't remember the steps for it.
    I went through the sqldriver tutorial https://doc.qt.io/qt-5/sql-driver.html, but as far as I remember I didn't build anything my self the last time.
    Currently I've simply installed PostgreSQL on my Windows PC

    I've added follwing to my .pro

    QT       += core gui sql
    
    INCLUDEPATH += E:\Development\PostgreSQL\bin
    LIBS += E:\Development\PostgreSQL\lib
    
    

    The QT seems to complain about the include paths, but VisualStudio seems to ignore that.

    Now the strange thing is, When debugging through the app, it seems like it fails to open the DB connection and can't insert anything to my Database obviously.

    And i get follwing debug output:

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

    But when I start the .exe directly through the windows explorer, everything works fine, which doesn't make any sense for me.

    Can anyone help?

    J 1 Reply Last reply 12 Feb 2019, 05:34
    0
    • S Slei
      11 Feb 2019, 23:11

      Hey,

      I'm currently having issues to get my old QT postgresql build working on a new pc.
      It was once working on my old one but I simply can't remember the steps for it.
      I went through the sqldriver tutorial https://doc.qt.io/qt-5/sql-driver.html, but as far as I remember I didn't build anything my self the last time.
      Currently I've simply installed PostgreSQL on my Windows PC

      I've added follwing to my .pro

      QT       += core gui sql
      
      INCLUDEPATH += E:\Development\PostgreSQL\bin
      LIBS += E:\Development\PostgreSQL\lib
      
      

      The QT seems to complain about the include paths, but VisualStudio seems to ignore that.

      Now the strange thing is, When debugging through the app, it seems like it fails to open the DB connection and can't insert anything to my Database obviously.

      And i get follwing debug output:

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

      But when I start the .exe directly through the windows explorer, everything works fine, which doesn't make any sense for me.

      Can anyone help?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 12 Feb 2019, 05:34 last edited by
      #2

      @Slei said in Adding PostgreSQL support:

      E:\Development\PostgreSQL\bin

      Are you sure this is the directory where include files are located?
      It should be something like E:\Development\PostgreSQL\include

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Slei
        wrote on 12 Feb 2019, 06:55 last edited by Slei 2 Dec 2019, 07:03
        #3

        yup thats correct, that was just something from my old project.
        tbh, I don't even know if those lines have any affect at all, probably I don't even need those.
        I also haven't seen any include/lib dir requirements in the tutorials.

        also libs has to be added with an -L prefix :
        LIBS += -L"E:\Development\PostgreSQL\lib"

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Feb 2019, 06:58 last edited by
          #4

          Hi,

          The PostgreSQL dlls are likely not found. Go to the Run part of the Project panel and add the path to them to the PATH environment variable.

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

          S 1 Reply Last reply 12 Feb 2019, 07:08
          2
          • S SGaist
            12 Feb 2019, 06:58

            Hi,

            The PostgreSQL dlls are likely not found. Go to the Run part of the Project panel and add the path to them to the PATH environment variable.

            S Offline
            S Offline
            Slei
            wrote on 12 Feb 2019, 07:08 last edited by Slei 2 Dec 2019, 07:22
            #5

            @SGaist
            I've added the postgresql lib path to the windows PATH env. variables already:

            postgresql install path "E:\Development\PostgreSQL\lib" and "E:\Development\PostgreSQL\bin"

            additionally I've added those lines now to the "Run Environment" Path variable settings in "Run" bit it seems like still cannot load the drivers

            The paths seem to work for executing the exe directly, since I can successfully execute sql stuff on the db, so maybe i'm still not adding the libs correctly

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Slei
              wrote on 12 Feb 2019, 07:25 last edited by Slei 2 Dec 2019, 07:29
              #6

              On visual studio I've now added the postgresql bin path directly and it seems to work. so there must be an issue with adding the libs inside the .pro file. Shouldn't it be enough to have those paths in the PATH env. variable?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Slei
                wrote on 12 Feb 2019, 07:40 last edited by
                #7

                Ok, not sure if that was the issue at the end, but I've moved the settings from Accoun Environment Variables to System Variables and now it seems to work, even though the account variables are in the Qt Run Path...

                About the Qt tutorial...
                In there it says I have to build the drivers myself, but in the end, I never had to build anything at all, can anyone explain what this is for? Is it just for building qt from source?
                For me this was quite confusing since it's the main tutorial that pops up when searching for "qt postresql tutorials"

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 12 Feb 2019, 22:45 last edited by
                  #8

                  Which tutorial are you refereeing to ?

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

                  S 1 Reply Last reply 13 Feb 2019, 01:01
                  0
                  • S SGaist
                    12 Feb 2019, 22:45

                    Which tutorial are you refereeing to ?

                    S Offline
                    S Offline
                    Slei
                    wrote on 13 Feb 2019, 01:01 last edited by
                    #9

                    @SGaist https://doc.qt.io/qt-5/sql-driver.html it's not a tutorial but something that comes first when you search for one.
                    At the beginning I though this step was necessary to be able to work with my db.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 13 Feb 2019, 22:48 last edited by
                      #10

                      The pre-built binary comes with a set of drivers. What happens usually is that you have to tell your application where to find the corresponding dependencies. If the version of of PostgreSQL you installed is different that the one used to build the plugin, then you will have to re-build it.

                      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

                      1/10

                      11 Feb 2019, 23:11

                      • Login

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