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
Qt 6.11 is out! See what's new in the release blog

Error Connecting to PostgreSQL Mac OS

Scheduled Pinned Locked Moved Solved Installation and Deployment
7 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.
  • G Offline
    G Offline
    GBRITO
    wrote on 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.

    jsulmJ 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @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 last edited by GBRITO
      #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

        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.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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
        0
        • jsulmJ jsulm

          @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 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
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 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
            0
            • Christian EhrlicherC Christian Ehrlicher

              So do you actually link against to Qt Sql module?

              G Offline
              G Offline
              GBRITO
              wrote on last edited by GBRITO
              #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...

              Christian EhrlicherC 1 Reply Last reply
              0
              • G GBRITO

                @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...

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 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
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @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 last edited by GBRITO
                  #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

                  • Login

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