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.
  • StokestackS Offline
    StokestackS Offline
    Stokestack
    wrote on 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!

    aha_1980A 1 Reply Last reply
    0
    • StokestackS Stokestack

      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!

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 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.

      StokestackS 1 Reply Last reply
      2
      • aha_1980A aha_1980

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

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

        Regards

        StokestackS Offline
        StokestackS Offline
        Stokestack
        wrote on 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)

        aha_1980A 1 Reply Last reply
        0
        • StokestackS Stokestack

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

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 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
          • StokestackS Offline
            StokestackS Offline
            Stokestack
            wrote on 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?

            aha_1980A 1 Reply Last reply
            0
            • StokestackS Stokestack

              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?

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 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.

              StokestackS 1 Reply Last reply
              0
              • aha_1980A aha_1980

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

                StokestackS Offline
                StokestackS Offline
                Stokestack
                wrote on 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?

                aha_1980A 1 Reply Last reply
                0
                • StokestackS Stokestack

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

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 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
                  • StokestackS Offline
                    StokestackS Offline
                    Stokestack
                    wrote on last edited by Stokestack
                    #9

                    Duh! Thanks for pointing that out!

                    1 Reply Last reply
                    1
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 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

                      StokestackS 2 Replies Last reply
                      2
                      • SGaistS SGaist

                        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.

                        StokestackS Offline
                        StokestackS Offline
                        Stokestack
                        wrote on last edited by Stokestack
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • SGaistS SGaist

                          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.

                          StokestackS Offline
                          StokestackS Offline
                          Stokestack
                          wrote on 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

                          • Login

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