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. Error Connecting to PostgreSQL Mac OS
Forum Updated to NodeBB v4.3 + New Features

Error Connecting to PostgreSQL Mac OS

Scheduled Pinned Locked Moved Solved Installation and Deployment
7 Posts 3 Posters 525 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.
  • G Offline
    G Offline
    GBRITO
    wrote on 6 May 2024, 01:15 last edited by
    #1

    Hi, I am trying to connect a Qt Application with PostgreSQL on a Mac running Big Sur (intel), my simple code is as follow:

    QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("EAPDB");
    db.setUserName("user");
    db.setPassword("pass");
    db.setPort(5432);

    if (db.open())
        ui->lblTest->setText("Connected");
    else
        ui->lblTest->setText("Not Connected");
    

    When I try to run the program the following error appears:
    Undefined symbols for architecture x86_64

    I follow instructions to change the path using install_name_tool but doesn't work.

    Hope one of you can help me.

    J 1 Reply Last reply 6 May 2024, 06:15
    0
    • C Christian Ehrlicher
      6 May 2024, 16:01

      @GBRITO said in Error Connecting to PostgreSQL Mac OS:

      I'm beginner in Qt,

      This is nothing Qt specific - if you use an external class then you must link against the library it contains. And each Qt class has a nice header which explains on how to do it. See e.g. QSqlDatabase.

      The QPSQL driver not loaded problem should be solved afterwards - one at a time.

      G Offline
      G Offline
      GBRITO
      wrote on 9 May 2024, 15:17 last edited by GBRITO 5 Sept 2024, 15:19
      #7

      Thanks @Christian-Ehrlicher for you guide, I read about linking the components and now the initial error about Undefined symbols for architecture x86_64 was fixed.

      I add the links to the CMakeLists.txt as follows:

      find_package(Qt6 REQUIRED COMPONENTS Sql)
      target_link_libraries(EAPSolution PRIVATE Qt${QT_VERSION_MAJOR}::Widgets PRIVATE Qt${QT_VERSION_MAJOR}::Sql)

      1 Reply Last reply
      1
      • G GBRITO
        6 May 2024, 01:15

        Hi, I am trying to connect a Qt Application with PostgreSQL on a Mac running Big Sur (intel), my simple code is as follow:

        QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
        db.setHostName("localhost");
        db.setDatabaseName("EAPDB");
        db.setUserName("user");
        db.setPassword("pass");
        db.setPort(5432);

        if (db.open())
            ui->lblTest->setText("Connected");
        else
            ui->lblTest->setText("Not Connected");
        

        When I try to run the program the following error appears:
        Undefined symbols for architecture x86_64

        I follow instructions to change the path using install_name_tool but doesn't work.

        Hope one of you can help me.

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 6 May 2024, 06:15 last edited by
        #2

        @GBRITO said in Error Connecting to PostgreSQL Mac OS:

        When I try to run the program the following error appears:
        Undefined symbols for architecture x86_64

        You mean when you try to build your application?
        Please post the whole error.

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

        G 1 Reply Last reply 6 May 2024, 13:10
        0
        • J jsulm
          6 May 2024, 06:15

          @GBRITO said in Error Connecting to PostgreSQL Mac OS:

          When I try to run the program the following error appears:
          Undefined symbols for architecture x86_64

          You mean when you try to build your application?
          Please post the whole error.

          G Offline
          G Offline
          GBRITO
          wrote on 6 May 2024, 13:10 last edited by
          #3

          @jsulm, you're right, the error appears when I try to build the applications, below is a screenshot of the complete error:

          925eaaa1-f83d-49d8-beeb-0e6b4d868818-image.png

          Thanks for your help

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 6 May 2024, 13:23 last edited by
            #4

            So do you actually link against to Qt Sql module?

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

            G 1 Reply Last reply 6 May 2024, 13:33
            0
            • C Christian Ehrlicher
              6 May 2024, 13:23

              So do you actually link against to Qt Sql module?

              G Offline
              G Offline
              GBRITO
              wrote on 6 May 2024, 13:33 last edited by GBRITO 5 Jun 2024, 13:49
              #5

              @Christian-Ehrlicher

              I'm not sure about your question, I'm beginner in Qt, I follow internet guide how to connect from Qt to PostgreSQL, also when I found the problem I tried to solve it using the install_name_tool in order to tell Qt to use the PostgreSQL drivers. But the error continues.

              Using the sqlbrowser application I have another error message, I know is not part of the application I'm trying to create, but that error leads me to use the install_name_tool.

              bcf0b88c-d40e-4e36-a331-d455d5dd0614-image.png

              In this application the PostgreSQL library is detected...

              C 1 Reply Last reply 6 May 2024, 16:01
              0
              • G GBRITO
                6 May 2024, 13:33

                @Christian-Ehrlicher

                I'm not sure about your question, I'm beginner in Qt, I follow internet guide how to connect from Qt to PostgreSQL, also when I found the problem I tried to solve it using the install_name_tool in order to tell Qt to use the PostgreSQL drivers. But the error continues.

                Using the sqlbrowser application I have another error message, I know is not part of the application I'm trying to create, but that error leads me to use the install_name_tool.

                bcf0b88c-d40e-4e36-a331-d455d5dd0614-image.png

                In this application the PostgreSQL library is detected...

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 6 May 2024, 16:01 last edited by
                #6

                @GBRITO said in Error Connecting to PostgreSQL Mac OS:

                I'm beginner in Qt,

                This is nothing Qt specific - if you use an external class then you must link against the library it contains. And each Qt class has a nice header which explains on how to do it. See e.g. QSqlDatabase.

                The QPSQL driver not loaded problem should be solved afterwards - one at a time.

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

                G 1 Reply Last reply 9 May 2024, 15:17
                1
                • C Christian Ehrlicher
                  6 May 2024, 16:01

                  @GBRITO said in Error Connecting to PostgreSQL Mac OS:

                  I'm beginner in Qt,

                  This is nothing Qt specific - if you use an external class then you must link against the library it contains. And each Qt class has a nice header which explains on how to do it. See e.g. QSqlDatabase.

                  The QPSQL driver not loaded problem should be solved afterwards - one at a time.

                  G Offline
                  G Offline
                  GBRITO
                  wrote on 9 May 2024, 15:17 last edited by GBRITO 5 Sept 2024, 15:19
                  #7

                  Thanks @Christian-Ehrlicher for you guide, I read about linking the components and now the initial error about Undefined symbols for architecture x86_64 was fixed.

                  I add the links to the CMakeLists.txt as follows:

                  find_package(Qt6 REQUIRED COMPONENTS Sql)
                  target_link_libraries(EAPSolution PRIVATE Qt${QT_VERSION_MAJOR}::Widgets PRIVATE Qt${QT_VERSION_MAJOR}::Sql)

                  1 Reply Last reply
                  1
                  • G GBRITO has marked this topic as solved on 9 May 2024, 15:20

                  7/7

                  9 May 2024, 15:17

                  • Login

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