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. Qt suddenly claims it can't find QSqlDatabase
Forum Updated to NodeBB v4.3 + New Features

Qt suddenly claims it can't find QSqlDatabase

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 2.7k Views 2 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.
  • S Offline
    S Offline
    Stokestack
    wrote on 23 Jun 2019, 07:21 last edited by Stokestack
    #1

    Hi all.

    I've decided to turn the core portion of my app into a library. I've made appropriate changes to the project file & added the Q_DECL_EXPORT macros.

    At some point (I have no idea what triggered it), compilation started failing on

    #include <QSqlDatabase>
    

    I have

    QT       += core bluetooth sql
    

    in the project file (where it always was) and haven't made any changes to my Qt installation. If I start typing that include line, it auto-completes "QSqlDatabase." Anybody have an idea here? Thanks!

    A 1 Reply Last reply 23 Jun 2019, 07:33
    0
    • S Stokestack
      23 Jun 2019, 07:21

      Hi all.

      I've decided to turn the core portion of my app into a library. I've made appropriate changes to the project file & added the Q_DECL_EXPORT macros.

      At some point (I have no idea what triggered it), compilation started failing on

      #include <QSqlDatabase>
      

      I have

      QT       += core bluetooth sql
      

      in the project file (where it always was) and haven't made any changes to my Qt installation. If I start typing that include line, it auto-completes "QSqlDatabase." Anybody have an idea here? Thanks!

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 23 Jun 2019, 07:33 last edited by aha_1980
      #2

      @Stokestack please re-run qmake and then rebuild the project.

      If the error persists, post the compiler command line leading to this error.

      Regards

      Qt has to stay free or it will die.

      S 1 Reply Last reply 23 Jun 2019, 07:48
      2
      • A aha_1980
        23 Jun 2019, 07:33

        @Stokestack please re-run qmake and then rebuild the project.

        If the error persists, post the compiler command line leading to this error.

        Regards

        S Offline
        S Offline
        Stokestack
        wrote on 23 Jun 2019, 07:48 last edited by Stokestack
        #3

        @aha_1980 Thanks for the response.

        For once, I had remembered to run qmake (and clean) and it didn't help.

        Here's the output. It's possible I haven't set this thing up to be a static lib correctly, but I don't know what might be wrong:

        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++1z  -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.12 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../AtomRemote-all/AtomRemote-mobile -I. -I../../AtomRemote-all/AtomRemote -I/Developer/Qt/5.12.3/clang_64/lib/QtQuick.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtGui.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtQml.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtNetwork.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/AGL.framework/Headers/ -I/Developer/Qt/5.12.3/clang_64/mkspecs/macx-clang -F/Developer/Qt/5.12.3/clang_64/lib -o main.o ../../AtomRemote-all/AtomRemote-mobile/main.cpp
        /Developer/Qt/5.12.3/clang_64/bin/rcc -name qml ../../AtomRemote-all/AtomRemote-mobile/qml.qrc -o qrc_qml.cpp
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++1z  -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.12 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../AtomRemote-all/AtomRemote-mobile -I. -I../../AtomRemote-all/AtomRemote -I/Developer/Qt/5.12.3/clang_64/lib/QtQuick.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtGui.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtQml.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtNetwork.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/AGL.framework/Headers/ -I/Developer/Qt/5.12.3/clang_64/mkspecs/macx-clang -F/Developer/Qt/5.12.3/clang_64/lib -o qrc_qml.o qrc_qml.cpp
        In file included from ../../AtomRemote-all/AtomRemote-mobile/main.cpp:5:
        In file included from ../../AtomRemote-all/AtomRemote/DBManager.h:10:
        ../../AtomRemote-all/AtomRemote/AtomSystemDAO.h:4:10: fatal error: 'QSqlDatabase' file not found
        #include <QSqlDatabase>
        

        ![alt text](0_1561276403428_projectStructure.png image url)

        A 1 Reply Last reply 23 Jun 2019, 07:54
        0
        • S Stokestack
          23 Jun 2019, 07:48

          @aha_1980 Thanks for the response.

          For once, I had remembered to run qmake (and clean) and it didn't help.

          Here's the output. It's possible I haven't set this thing up to be a static lib correctly, but I don't know what might be wrong:

          /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++1z  -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.12 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../AtomRemote-all/AtomRemote-mobile -I. -I../../AtomRemote-all/AtomRemote -I/Developer/Qt/5.12.3/clang_64/lib/QtQuick.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtGui.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtQml.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtNetwork.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/AGL.framework/Headers/ -I/Developer/Qt/5.12.3/clang_64/mkspecs/macx-clang -F/Developer/Qt/5.12.3/clang_64/lib -o main.o ../../AtomRemote-all/AtomRemote-mobile/main.cpp
          /Developer/Qt/5.12.3/clang_64/bin/rcc -name qml ../../AtomRemote-all/AtomRemote-mobile/qml.qrc -o qrc_qml.cpp
          /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++1z  -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.12 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../AtomRemote-all/AtomRemote-mobile -I. -I../../AtomRemote-all/AtomRemote -I/Developer/Qt/5.12.3/clang_64/lib/QtQuick.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtGui.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtQml.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtNetwork.framework/Headers -I/Developer/Qt/5.12.3/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode10.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/AGL.framework/Headers/ -I/Developer/Qt/5.12.3/clang_64/mkspecs/macx-clang -F/Developer/Qt/5.12.3/clang_64/lib -o qrc_qml.o qrc_qml.cpp
          In file included from ../../AtomRemote-all/AtomRemote-mobile/main.cpp:5:
          In file included from ../../AtomRemote-all/AtomRemote/DBManager.h:10:
          ../../AtomRemote-all/AtomRemote/AtomSystemDAO.h:4:10: fatal error: 'QSqlDatabase' file not found
          #include <QSqlDatabase>
          

          ![alt text](0_1561276403428_projectStructure.png image url)

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 23 Jun 2019, 07:54 last edited by
          #4

          @Stokestack Well, I don't see an include path for QtSql in your compiler call. Are you sure you added QT += SQL to the correct .pro file?

          Because it seems you have a SUBDIRS project with multiple .pro files.

          Qt has to stay free or it will die.

          1 Reply Last reply
          2
          • S Offline
            S Offline
            Stokestack
            wrote on 23 Jun 2019, 08:00 last edited by Stokestack
            #5

            Thanks! Well, it's in the .pro file that builds the lib that uses SQL.

            But, sure enough, also adding it to the .pro file that will link with the library eliminates the error. All I do in that project so far is instantiate one of the objects from the lib.

            So a Qt project that uses a lib must also add all of the modules that the lib uses to its own project file?

            A 1 Reply Last reply 23 Jun 2019, 08:04
            0
            • S Stokestack
              23 Jun 2019, 08:00

              Thanks! Well, it's in the .pro file that builds the lib that uses SQL.

              But, sure enough, also adding it to the .pro file that will link with the library eliminates the error. All I do in that project so far is instantiate one of the objects from the lib.

              So a Qt project that uses a lib must also add all of the modules that the lib uses to its own project file?

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 23 Jun 2019, 08:04 last edited by
              #6

              @Stokestack said in Qt suddenly claims it can't find QSqlDatabase:

              So a Qt project that uses a lib must also add all of the modules that the lib uses to its own project file?

              No. Every lib is on its own. You can have a lib that uses QtSql, and an app that just uses this lib. But if you use QtSql directly in your app, you have to add the module there too.

              Qt has to stay free or it will die.

              S 1 Reply Last reply 23 Jun 2019, 08:08
              0
              • A aha_1980
                23 Jun 2019, 08:04

                @Stokestack said in Qt suddenly claims it can't find QSqlDatabase:

                So a Qt project that uses a lib must also add all of the modules that the lib uses to its own project file?

                No. Every lib is on its own. You can have a lib that uses QtSql, and an app that just uses this lib. But if you use QtSql directly in your app, you have to add the module there too.

                S Offline
                S Offline
                Stokestack
                wrote on 23 Jun 2019, 08:08 last edited by Stokestack
                #7

                @aha_1980 Well, this is a bit perplexing then. All I do in this app is

                	DBManager& DBMgr = DBManager::getInstance();
                
                

                There is no further use of anything from the lib, although I do say this:

                	QQmlContext* pContext = engine.rootContext();
                	pContext->setContextProperty("DBMgr", &DBMgr);
                

                Does exposing the whole object to the "client" project somehow trigger this requirement?

                A 1 Reply Last reply 23 Jun 2019, 08:24
                0
                • S Stokestack
                  23 Jun 2019, 08:08

                  @aha_1980 Well, this is a bit perplexing then. All I do in this app is

                  	DBManager& DBMgr = DBManager::getInstance();
                  
                  

                  There is no further use of anything from the lib, although I do say this:

                  	QQmlContext* pContext = engine.rootContext();
                  	pContext->setContextProperty("DBMgr", &DBMgr);
                  

                  Does exposing the whole object to the "client" project somehow trigger this requirement?

                  A Offline
                  A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 23 Jun 2019, 08:24 last edited by
                  #8

                  @Stokestack

                  Does exposing the whole object to the "client" project somehow trigger this requirement?

                  No, now I've got it:

                  In file included from ../../AtomRemote-all/AtomRemote-mobile/main.cpp:5:
                  In file included from ../../AtomRemote-all/AtomRemote/DBManager.h:10:
                  ../../AtomRemote-all/AtomRemote/AtomSystemDAO.h:4:10: fatal error: 'QSqlDatabase' file not found

                  You just need to read the error message carefully.

                  You include QSqlDatabase in your DBManager.h, which in turn is included from your app project. Therefore you get the need to find the Qt database classes in your include path.

                  Refactor your lib to get rid of that. E.g. you can use the following forward declaration in your header file:

                  #include <QObject>
                  
                  QT_BEGIN_NAMESPACE
                  class QSqlDatabase;
                  QT_END_NAMESPACE
                  
                  class DBManager {
                  
                   // ...
                  
                  private:
                    QSqlDatabase *m_db = nullptr;
                  }
                  

                  and only include QSqlDatabase in the corresponding DBManager.cpp file.

                  Regards

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  3
                  • S Offline
                    S Offline
                    Stokestack
                    wrote on 23 Jun 2019, 09:15 last edited by Stokestack
                    #9

                    Duh! Thanks for pointing that out!

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 23 Jun 2019, 18:59 last edited by
                      #10

                      Hi,

                      One thing to take into account: there's no need to store any local QSqlDatabase variable (or pointer). This class already manages all connections for you.

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

                      S 2 Replies Last reply 23 Jun 2019, 20:09
                      2
                      • S SGaist
                        23 Jun 2019, 18:59

                        Hi,

                        One thing to take into account: there's no need to store any local QSqlDatabase variable (or pointer). This class already manages all connections for you.

                        S Offline
                        S Offline
                        Stokestack
                        wrote on 23 Jun 2019, 20:09 last edited by Stokestack
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • S SGaist
                          23 Jun 2019, 18:59

                          Hi,

                          One thing to take into account: there's no need to store any local QSqlDatabase variable (or pointer). This class already manages all connections for you.

                          S Offline
                          S Offline
                          Stokestack
                          wrote on 24 Jun 2019, 04:15 last edited by
                          #12

                          @SGaist Just came back to say to say thanks again for thinking to add this remark. I was indeed pointlessly storing the DB connection in member variables and complicating my task.

                          1 Reply Last reply
                          0

                          5/12

                          23 Jun 2019, 08:00

                          • Login

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