Unsolved QSqlDatabase
-
The following include gives an error:
fatal error: QSqlDatabase: No such file or directory
#include <QSqlDatabase>
^~~~~~~~~~~~~~
compilation terminated.I have god MySQL installed and I am using CMake. I presume I have to tell CMake about QSqlDatabase in CMakeLists.txt, but how do I do that? As I understand it, QSqlDatabase is part of Qt, so I should not need to install a dev-lib for MySQL?
-
@Buller said in QSqlDatabase:
I presume I have to tell CMake about QSqlDatabase in CMakeLists.txt, but how do I do that?
You have to search and link against the target Qt5::Sql - see https://doc.qt.io/qt-5/cmake-get-started.html#imported-targets
-
hi, if you use the Qt Creator or qmaker, you can add the "sql" on first line of .pro file. which make its first line looks like,
qt += sql (other dll file you may used)
-
I am not using Creator, but Kdevelop and CMake, on Kubuntu. What I cannot work out is how I add "qt += sql" in the CMakeList.txt file, and I cannot find it in the Qt documentation.
-
@Buller Hi, the answer of @Christian-Ehrlicher along with the link he posted applies the same in your case.
-
I am still struggling with this. In CMakeLists.txt I have
Find Qt libraries
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5 COMPONENTS Core REQUIRED)
get_target_property(QtCore_location Qt5::Core LOCATION)
#get_target_property(QSql location Qt5::Sql LOCATION)but I get the same error:
fatal error: QtSql: No such file or directory
#include <QtSql>
^~~~~~~
compilation terminated.I noticed that I have a mix of Qt4 and Qt5 stuff:
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqldriver.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsql.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlrecord.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqltablemodel.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqldriverplugin.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlfield.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlquery.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlindex.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlquerymodel.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqldatabase.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlrelationaldelegate.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlrelationaltablemodel.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlresult.h
/usr/include/x86_64-linux-gnu/qt5/QtSql/qsqlerror.h
/usr/include/qt4/QtSql/qsqldriver.h
/usr/include/qt4/QtSql/qsql_psql.h
/usr/include/qt4/QtSql/qsql.h
/usr/include/qt4/QtSql/qsqlrecord.h
/usr/include/qt4/QtSql/qsqltablemodel.h
etc.Would that be a problem?
-
@Buller said in QSqlDatabase:
Would that be a problem?
Again: you have to search for Qt5::Sql with find_package() the way you do it with QtWidgets amd also have to link against this target the way you do it with QtWidgets...