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

QSqlDatabase

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 3.3k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    Buller
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

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

      1 Reply Last reply
      2
      • H Offline
        H Offline
        hehedaozuiteng
        wrote on last edited by
        #3

        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)
        
        1 Reply Last reply
        1
        • B Offline
          B Offline
          Buller
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Buller Hi, the answer of @Christian-Ehrlicher along with the link he posted applies the same in your case.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • B Offline
              B Offline
              Buller
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

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

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

                1 Reply Last reply
                1

                • Login

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