Error Connecting to PostgreSQL Mac OS
-
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_64I follow instructions to change the path using install_name_tool but doesn't work.
Hope one of you can help me.
-
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) -
@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_64You mean when you try to build your application?
Please post the whole error. -
So do you actually link against to Qt Sql module?
-
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.
In this application the PostgreSQL library is detected...
-
@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.
-
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) -