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. Qt cannot connect Postgresql database different pc
QtWS25 Last Chance

Qt cannot connect Postgresql database different pc

Scheduled Pinned Locked Moved Solved General and Desktop
qsqlqsqldatabasepostgresqldatabaseqpsql
14 Posts 3 Posters 1.1k 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.
  • J Offline
    J Offline
    Joe von Habsburg
    wrote on 27 Mar 2024, 06:23 last edited by
    #1

    I have a qt application. i am using postgresql as a database. while i have no problems connecting to the database on my own computer, i have problems on another computer. do i need to make any settings in qt or on the computer?

    J 1 Reply Last reply 27 Mar 2024, 07:22
    0
    • J Joe von Habsburg
      27 Mar 2024, 06:23

      I have a qt application. i am using postgresql as a database. while i have no problems connecting to the database on my own computer, i have problems on another computer. do i need to make any settings in qt or on the computer?

      J Offline
      J Offline
      JonB
      wrote on 27 Mar 2024, 07:22 last edited by
      #2

      @Joe-von-Habsburg
      Presumably you do that by specifying the other computer's name name/IP address for the database to connect to? So you have to make sure (a) the IP address is right, (b) any firewalls let the port through and (c) you have the necessary permissions to access that database and its tables, e.g. your username is acceptable or whatever. What/when do you get an error, what does it say, is it at connection time or when you try to execute a SQL command against a table?

      J 1 Reply Last reply 27 Mar 2024, 07:51
      1
      • J JonB
        27 Mar 2024, 07:22

        @Joe-von-Habsburg
        Presumably you do that by specifying the other computer's name name/IP address for the database to connect to? So you have to make sure (a) the IP address is right, (b) any firewalls let the port through and (c) you have the necessary permissions to access that database and its tables, e.g. your username is acceptable or whatever. What/when do you get an error, what does it say, is it at connection time or when you try to execute a SQL command against a table?

        J Offline
        J Offline
        Joe von Habsburg
        wrote on 27 Mar 2024, 07:51 last edited by Joe von Habsburg
        #3

        @JonB

        my database that's it.

        I take release on qtcreater and I add libs (windeployqt --quick) to my computer and run other computer.

        I crate database with pgadmin and its name is test. they are same.

            const QString DATABASE_HOST_NAME = "localhost";
            const int DATABASE_HOST_PORT = 5432;
            const QString DATABASE_NAME = "test";
            const QString DATABASE_USER_NAME = "postgres";
            const QString DATABASE_USER_PASSWORD = "postgres";
        

        @jsulm said in Qt cannot connect Postgresql database different pc:

        How should this work if you want to connect to SQL server running on another computer?!

        I download database to other computer. it will work local

        J 1 Reply Last reply 27 Mar 2024, 07:52
        0
        • J Joe von Habsburg
          27 Mar 2024, 07:51

          @JonB

          my database that's it.

          I take release on qtcreater and I add libs (windeployqt --quick) to my computer and run other computer.

          I crate database with pgadmin and its name is test. they are same.

              const QString DATABASE_HOST_NAME = "localhost";
              const int DATABASE_HOST_PORT = 5432;
              const QString DATABASE_NAME = "test";
              const QString DATABASE_USER_NAME = "postgres";
              const QString DATABASE_USER_PASSWORD = "postgres";
          

          @jsulm said in Qt cannot connect Postgresql database different pc:

          How should this work if you want to connect to SQL server running on another computer?!

          I download database to other computer. it will work local

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 27 Mar 2024, 07:52 last edited by
          #4

          @Joe-von-Habsburg said in Qt cannot connect Postgresql database different pc:

          const QString DATABASE_HOST_NAME = "localhost";

          How should this work if you want to connect to SQL server running on another computer?!

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

          J 1 Reply Last reply 27 Mar 2024, 08:10
          0
          • J jsulm
            27 Mar 2024, 07:52

            @Joe-von-Habsburg said in Qt cannot connect Postgresql database different pc:

            const QString DATABASE_HOST_NAME = "localhost";

            How should this work if you want to connect to SQL server running on another computer?!

            J Offline
            J Offline
            Joe von Habsburg
            wrote on 27 Mar 2024, 08:10 last edited by
            #5

            @jsulm

            I may not have been understood.

            1. I create qt app on my computer and work on local. I use postgresql server and I can connect it. I take release on qtcreator. I add libs by windeployqt commond line.

            2. I send release file to other computer.

            3. I setup postgresql to other computer and it has same properties (databse name, username, user password, port)

            But it could not connect. I wonder. do I need to make any additions when I get the release of the application? Or do you have any offer?

            J 2 Replies Last reply 27 Mar 2024, 08:14
            0
            • J Joe von Habsburg
              27 Mar 2024, 08:10

              @jsulm

              I may not have been understood.

              1. I create qt app on my computer and work on local. I use postgresql server and I can connect it. I take release on qtcreator. I add libs by windeployqt commond line.

              2. I send release file to other computer.

              3. I setup postgresql to other computer and it has same properties (databse name, username, user password, port)

              But it could not connect. I wonder. do I need to make any additions when I get the release of the application? Or do you have any offer?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 27 Mar 2024, 08:14 last edited by
              #6

              @Joe-von-Habsburg Then please add error handling to your application to get more information about the issue.
              https://doc.qt.io/qt-6/qsqldatabase.html#lastError

              Also, can you connect to the SQL server using the PostgreSQL client?

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

              J 1 Reply Last reply 27 Mar 2024, 08:33
              0
              • J Joe von Habsburg
                27 Mar 2024, 08:10

                @jsulm

                I may not have been understood.

                1. I create qt app on my computer and work on local. I use postgresql server and I can connect it. I take release on qtcreator. I add libs by windeployqt commond line.

                2. I send release file to other computer.

                3. I setup postgresql to other computer and it has same properties (databse name, username, user password, port)

                But it could not connect. I wonder. do I need to make any additions when I get the release of the application? Or do you have any offer?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 27 Mar 2024, 08:15 last edited by
                #7

                @Joe-von-Habsburg Also, check whether the sql plug-in was loaded: set QT_DEBUG_PLUGINS env variable before starting your app (see https://doc.qt.io/qt-6/debug.html).

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

                1 Reply Last reply
                0
                • J jsulm
                  27 Mar 2024, 08:14

                  @Joe-von-Habsburg Then please add error handling to your application to get more information about the issue.
                  https://doc.qt.io/qt-6/qsqldatabase.html#lastError

                  Also, can you connect to the SQL server using the PostgreSQL client?

                  J Offline
                  J Offline
                  Joe von Habsburg
                  wrote on 27 Mar 2024, 08:33 last edited by
                  #8

                  @jsulm said in Qt cannot connect Postgresql database different pc:

                  Also, can you connect to the SQL server using the PostgreSQL client?

                  yes I can connect by pgadmin and I can do anything (insert, delete, select)

                  J 1 Reply Last reply 27 Mar 2024, 08:45
                  0
                  • J Joe von Habsburg
                    27 Mar 2024, 08:33

                    @jsulm said in Qt cannot connect Postgresql database different pc:

                    Also, can you connect to the SQL server using the PostgreSQL client?

                    yes I can connect by pgadmin and I can do anything (insert, delete, select)

                    J Offline
                    J Offline
                    JonB
                    wrote on 27 Mar 2024, 08:45 last edited by
                    #9

                    @Joe-von-Habsburg said in Qt cannot connect Postgresql database different pc:

                    yes I can connect by pgadmin and I can do anything (insert, delete, select)

                    So I said earlier:

                    and (c) you have the necessary permissions to access that database and its tables, e.g. your username is acceptable or whatever.

                    It does not sound like you are passing an acceptable user? If you say it works via pgadmin is that using username postgres as your code does?

                    In any case please help yourself and us by following @jsulm's

                    Then please add error handling to your application to get more information about the issue.

                    You still have not told us which statement it fails on and what the error is (with lastError() for extended information). You should always put in such error handling, both to help you during development and for the end user to report if it goes wrong for whatever reason at runtime/after deployment.

                    J 1 Reply Last reply 27 Mar 2024, 09:24
                    1
                    • J JonB
                      27 Mar 2024, 08:45

                      @Joe-von-Habsburg said in Qt cannot connect Postgresql database different pc:

                      yes I can connect by pgadmin and I can do anything (insert, delete, select)

                      So I said earlier:

                      and (c) you have the necessary permissions to access that database and its tables, e.g. your username is acceptable or whatever.

                      It does not sound like you are passing an acceptable user? If you say it works via pgadmin is that using username postgres as your code does?

                      In any case please help yourself and us by following @jsulm's

                      Then please add error handling to your application to get more information about the issue.

                      You still have not told us which statement it fails on and what the error is (with lastError() for extended information). You should always put in such error handling, both to help you during development and for the end user to report if it goes wrong for whatever reason at runtime/after deployment.

                      J Offline
                      J Offline
                      Joe von Habsburg
                      wrote on 27 Mar 2024, 09:24 last edited by
                      #10

                      @JonB problem is driver could not be loaded. how can I add it?

                      J 1 Reply Last reply 27 Mar 2024, 09:27
                      0
                      • J Joe von Habsburg
                        27 Mar 2024, 09:24

                        @JonB problem is driver could not be loaded. how can I add it?

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 27 Mar 2024, 09:27 last edited by
                        #11

                        @Joe-von-Habsburg said in Qt cannot connect Postgresql database different pc:

                        how can I add it?

                        Did you also deploy the PostgreSQL client library together with your app?
                        Please post the output of the application after running it with QT_DEBUG_PLUGINS set, else we can only guess...

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

                        J 1 Reply Last reply 27 Mar 2024, 13:55
                        0
                        • J jsulm
                          27 Mar 2024, 09:27

                          @Joe-von-Habsburg said in Qt cannot connect Postgresql database different pc:

                          how can I add it?

                          Did you also deploy the PostgreSQL client library together with your app?
                          Please post the output of the application after running it with QT_DEBUG_PLUGINS set, else we can only guess...

                          J Offline
                          J Offline
                          Joe von Habsburg
                          wrote on 27 Mar 2024, 13:55 last edited by
                          #12

                          @jsulm said in Qt cannot connect Postgresql database different pc:

                          Did you also deploy the PostgreSQL client library together with your app?

                          How can I do it? I do not know. I know problem is driver but how I am able to add it? if you could help me with this I would appreciate it. what dlls should I add or what should I add to cmake?

                          @jsulm said in Qt cannot connect Postgresql database different pc:

                          QT_DEBUG

                          I can not use Debug. I use release profile on qtcreator

                          J 1 Reply Last reply 27 Mar 2024, 14:02
                          0
                          • J Joe von Habsburg
                            27 Mar 2024, 13:55

                            @jsulm said in Qt cannot connect Postgresql database different pc:

                            Did you also deploy the PostgreSQL client library together with your app?

                            How can I do it? I do not know. I know problem is driver but how I am able to add it? if you could help me with this I would appreciate it. what dlls should I add or what should I add to cmake?

                            @jsulm said in Qt cannot connect Postgresql database different pc:

                            QT_DEBUG

                            I can not use Debug. I use release profile on qtcreator

                            J Offline
                            J Offline
                            JonB
                            wrote on 27 Mar 2024, 14:02 last edited by
                            #13

                            @Joe-von-Habsburg
                            @jsulm did not ask you about QT_DEBUG or Debug. He asked you to set environment variable QT_DEBUG_PLUGINS (to value 1) before running your program. That will show diagnostic output which you will need to see what is happening/missing. You can look it up in the docs if you wish.

                            J 1 Reply Last reply 27 Mar 2024, 14:43
                            0
                            • J JonB
                              27 Mar 2024, 14:02

                              @Joe-von-Habsburg
                              @jsulm did not ask you about QT_DEBUG or Debug. He asked you to set environment variable QT_DEBUG_PLUGINS (to value 1) before running your program. That will show diagnostic output which you will need to see what is happening/missing. You can look it up in the docs if you wish.

                              J Offline
                              J Offline
                              Joe von Habsburg
                              wrote on 27 Mar 2024, 14:43 last edited by Joe von Habsburg
                              #14

                              @JonB I do not understand anything. Please could you give more informantion.

                              Note : app release folder has
                              a476d8a3-0275-4b95-be08-69e8e7ca83ca-image.png

                              I solved the problem :)

                              I add lib files from Postgresql to release folder
                              341075a5-d9d5-4598-9bb3-6bbae3cee52c-image.png

                              and it works. thank you @jsulm and @JonB

                              1 Reply Last reply
                              0
                              • J Joe von Habsburg has marked this topic as solved on 27 Mar 2024, 14:49

                              3/14

                              27 Mar 2024, 07:51

                              topic:navigator.unread, 11
                              • Login

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