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. How to connect Qt with postgreSQL?
Forum Updated to NodeBB v4.3 + New Features

How to connect Qt with postgreSQL?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 6 Posters 17.7k 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.
  • V Offline
    V Offline
    vIJI
    wrote on last edited by vIJI
    #4

    Thank you for replying, I am sorry, i am the beginner to Qt so will you please help me with the steps.

    Thank you.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vIJI
      wrote on last edited by
      #5

      @mcosta , i tried running those commands in terminal but the response was..as follows

      root@rcdtcpu24:/# cd $QTDIR/src/plugins/sqldrivers/psql
      bash: cd: /src/plugins/sqldrivers/psql: No such file or directory
      root@rcdtcpu24:/# qmake "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/usr/lib -lpq" psql.pro
      Cannot find file: psql.pro.
      root@rcdtcpu24:/# make
      make: *** No targets specified and no makefile found. Stop.

      Please do help with the steps....

      siropS 1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #6

        You should read the output more carefully:
        bash: cd: /src/plugins/sqldrivers/psql: No such file or directory

        That means there is no /src/plugins/sqldrivers/psql directory.
        QTDIR is not set. Just use the whole path to Qt sources directly.

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

        1 Reply Last reply
        1
        • V vIJI

          @mcosta , i tried running those commands in terminal but the response was..as follows

          root@rcdtcpu24:/# cd $QTDIR/src/plugins/sqldrivers/psql
          bash: cd: /src/plugins/sqldrivers/psql: No such file or directory
          root@rcdtcpu24:/# qmake "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/usr/lib -lpq" psql.pro
          Cannot find file: psql.pro.
          root@rcdtcpu24:/# make
          make: *** No targets specified and no makefile found. Stop.

          Please do help with the steps....

          siropS Offline
          siropS Offline
          sirop
          wrote on last edited by
          #7

          @vIJI
          So you seem to be on Linux?

          If you have an installation of Postgres on your machine, then you have to find out
          where Postgres include and lib directories are.

          The include these paths into your Qt project file (yourproject.pro).

          To be, or not to be: that is the question:
          Whether ’tis nobler in the mind to suffer
          The slings and arrows of outrageous fortune,
          Or to take arms against a sea of troubles,
          And by opposing end them?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vIJI
            wrote on last edited by vIJI
            #8

            Nope its not working......
            i have added them, the location was just "/usr"....

            unix:INCLUDEPATH += /usr/include/
            in .pro file but im unfortunate to get it success..

            can you tell me how to build it step by step please if you dont mind...

            thank you.

            1 Reply Last reply
            0
            • siropS sirop

              I think you can avoid the necessity of the Qt plugin database driver by using Postgres libs directly with something like that in your .pro file:

              win32:INCLUDEPATH += "C:/PostgreSQL/9.4/include"
              unix:INCLUDEPATH += /usr/include/postgresql
              
              win32:LIBS += "C:/PostgreSQL/9.4/lib/libpq.lib"
              unix:LIBS += -L/usr/lib -lpq
              

              Of course, your Qt compiler and the compiler, which the Postgres libpq was built with,
              should be the same.

              This is not the level of abstraction you achieve with QPSQL driver but I guess you get less overhead by simply writing a C++ Wrapper for libpq C.

              M Offline
              M Offline
              mcosta
              wrote on last edited by
              #9

              @sirop The code posted uses Qt to connect to the DB; so he MUST use the plugin.

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

              siropS 1 Reply Last reply
              0
              • M mcosta

                @sirop The code posted uses Qt to connect to the DB; so he MUST use the plugin.

                siropS Offline
                siropS Offline
                sirop
                wrote on last edited by sirop
                #10

                @mcosta

                You are right about the code connecting to the DB.
                But it is not true that you have to use QSql* in order to connect to the DB.
                Postgres has C API for this purpose which one can easily write a C++ wrapper for.

                So my advice was: if Qt way is too abstract, do it with a C++ wrapper of Postgres C API.

                To be, or not to be: that is the question:
                Whether ’tis nobler in the mind to suffer
                The slings and arrows of outrageous fortune,
                Or to take arms against a sea of troubles,
                And by opposing end them?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mcosta
                  wrote on last edited by
                  #11

                  @sirop, You're right: you don't have to use Qt to connect to the DB but the topic of the thread is How to connect Qt with PostgreSQL so probably the author wants to understand how to do it.

                  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
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    Hi,

                    @vIJI First thing to check: How did you install Qt ? Are you using the Online Installer ? Your distribution's package manager ?

                    If the former: did you install the Qt sources ? You can make that through the installer.
                    If the later, what distribution is it ? Most of them provide all database drivers.

                    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
                    • M Offline
                      M Offline
                      MuratCan
                      wrote on last edited by
                      #13

                      Hello,
                      First of all, you get this error because the postgresql you have installed is missing. You need to install the postgresql ODBC package. After installing it, you need to introduce the / bin file into the system environment or .pro
                      Good luck.

                      1 Reply Last reply
                      1

                      • Login

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