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. Getting QSqlError "Driver not loaded"
Qt 6.11 is out! See what's new in the release blog

Getting QSqlError "Driver not loaded"

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 394 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.
  • D Offline
    D Offline
    DiBosco
    wrote last edited by
    #1

    I have found a few posts referring to this kind of error and they say to ensure you enable QT_DEBUG_PLUGINS so it will tell you why the driver isn't loaded. However, if I do that I just get this:

    qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QPSQL")
    qt.core.plugin.factoryloader: checking directory path "C:/Software/Qt/MT47/MT47SW01/build/Desktop_Qt_6_10_2_MinGW_64_bit-Release/release/sqldrivers" ...
    qt.sql.qsqldatabase: QSqlDatabase: can not load requested driver 'QMYSQL', available drivers: QIBASE QSQLITE QMIMER QOCI QODBC QPSQL
    

    As the only reference to it.

    A bit of background on this:

    I have had this working on Linux for ages no problem, but need to give some Windows users the same functionality. So I have checked out the code and built it, it builds and runs fine, but I get this "Driver not loaded" error.

    I have tried installing mysql drivers from Oracle no no avail. I've found some post saying you need to build them so I went down that rabbit hole and then saw this:

    Note: As of MySQL 8.0.19, the C Connector is no longer offered as a standalone installable component. Instead, you can get mysql.h and libmysql.* by installing the full MySQL Server (x64 only) or the MariaDB C Connector.
    

    And eventually mabnaged to install libmariadb.lib and libmariadb.dll (as we are using Maria db on the server side).

    Adding this:

    win32: LIBS += -L"C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib" -llibmariadb

    To my project file, but I still get the same error.

    I have tried using both MSVC and mingw,

    I now am thinking I am missing an important issue here.

    Here is my project file:

    QT       += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++17
    LIBS += -lsqlUtitlities
    INCLUDEPATH += /usr/local/include/
    
    win32: LIBS += -L"C:\Software\Qt\MT47\MT47SW02\build\Desktop_Qt_6_10_2_MinGW_64_bit-Release\release" -llibsqlUtitlities
    win32: INCLUDEPATH += "..\MT47SW02"
    win32: LIBS += -L"C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib" -llibmariadb
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        commonsqlqueries.cpp \
        ecr.cpp \
        logindialogue.cpp \
        main.cpp \
        mainwindow.cpp \
        mutcodedialogue.cpp \
        mutcodesearch.cpp \
        tableexplorer.cpp
    
    HEADERS += \
        commonsqlqueries.h \
        ecr.h \
        logindialogue.h \
        mainwindow.h \
        mutcodedialogue.h \
        mutcodesearch.h \
        tableexplorer.h
    
    FORMS += \
        ecr.ui \
        logindialogue.ui \
        mainwindow.ui \
        mutcodedialogue.ui \
        mutcodesearch.ui \
        tableexplorer.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    Anyone able to give me a nudge here as to what I am missing?

    Thanks!

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

      You have to build the Qt sql driver for MySQL by yourself for legal reasons as described here: https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows

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

      D 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        You have to build the Qt sql driver for MySQL by yourself for legal reasons as described here: https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows

        D Offline
        D Offline
        DiBosco
        wrote last edited by
        #3

        @Christian-Ehrlicher said in Getting QSqlError "Driver not loaded":

        You have to build the Qt sql driver for MySQL by yourself for legal reasons as described here: https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows

        I did see that and I'd [mis]understood it as saying DLLs were now being supplied.

        So, looking at this bit of info:

        mkdir build-sqldrivers
        cd build-sqldrivers
        qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMySQL_ROOT="C:\mysql-8.0.22-winx64"
        cmake --build .
        cmake --install .
        

        I have some questions about that.

        These two lines:

        mkdir build-sqldrivers
        cd build-sqldrivers
        

        What directory are these new subdirectories to be put? Or does it not matter?

        qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMySQL_ROOT="C:\mysql-8.0.22-winx64"
        

        This <qt_installation_path> I am assuming is where that particular release of Qt lives. So in my case this is

        c:\Qt6\6.10.2

        However, that does not have a source directory. So, do I have to download the Qt source here first?

        qt_installation_path>\<platform>
        
        

        What is platform here?

        DMySQL_ROOT="C:\mysql-8.0.22-winx64
        

        Is this, for me:

        C:\Program Files\MariaDB\MariaDB Connector C 64-bit

        Where I have subdirectories:

        lib which has mariadb.dll

        And:

        include which has mysql.h

        And at the end of this, what will it actually create in terms of a DLL? Something like QMAriadb.dll or QMysql.dll and it's basically jiust a wrapper for the already supplied mariadb.dll?

        Thanks.

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

          Hi,

          You can put the build wherever you want outside of Qt's sources.

          The <qt_installation_path> is the root where you have Qt. In your case it seems to be C:/Qt6.

          You have to download the Qt sources that matches the version you want to build the driver for. You can do that through the Maintenance Tool.

          platform is what you have after C:/Qt6/6.10.2

          It will create a plugin that will use the library you supplied.

          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
          • D Offline
            D Offline
            DiBosco
            wrote last edited by DiBosco
            #5

            OK, thanks to everyone, I now have it compiled and running. It fought me. A lot.

            I had to install cmake, then ninja, then reboot. Then eventually worked out that I was trying to use Mingw parts with MSVC compiler, so rebuilt against Qt using Mingw as the compiler and it eventually worked.

            Uff, it's always easier on Linux! :D

            Why do you have to compile on Windows when on Linux this just works? None of this having to build libraries stuff!

            Christian EhrlicherC 1 Reply Last reply
            0
            • D DiBosco

              OK, thanks to everyone, I now have it compiled and running. It fought me. A lot.

              I had to install cmake, then ninja, then reboot. Then eventually worked out that I was trying to use Mingw parts with MSVC compiler, so rebuilt against Qt using Mingw as the compiler and it eventually worked.

              Uff, it's always easier on Linux! :D

              Why do you have to compile on Windows when on Linux this just works? None of this having to build libraries stuff!

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote last edited by Christian Ehrlicher
              #6

              @DiBosco said in Getting QSqlError "Driver not loaded":

              Why do you have to compile on Windows when on Linux this just works?

              You have to build the Qt sql driver for MySQL by yourself for legal reasons

              And there is no need to compile Qt by yourself. Mingw and msvc binaries are provided by the installer and the MySQL plugin compiles with both.

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

              D 1 Reply Last reply
              0
              • Joe von HabsburgJ Offline
                Joe von HabsburgJ Offline
                Joe von Habsburg
                wrote last edited by
                #7

                I use for PostgreSQL, maybe help you

                set(POSTGRESQL_DLL_DIR "C:/Program Files/PostgreSQL/17/bin")
                foreach(dll IN ITEMS
                    libpq.dll
                    libssl-3-x64.dll
                    libcrypto-3-x64.dll
                    libiconv-2.dll
                    libintl-9.dll
                    libpgtypes.dll
                    libwinpthread-1.dll
                    libxml2.dll
                    libxslt.dll
                    libzstd.dll
                    libcurl.dll
                    libecpg.dll
                    libecpg_compat.dll
                    liblz4.dll
                )
                    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy_if_different
                            "${POSTGRESQL_DLL_DIR}/${dll}"
                            $<TARGET_FILE_DIR:${PROJECT_NAME}>
                    )
                endforeach()
                
                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @DiBosco said in Getting QSqlError "Driver not loaded":

                  Why do you have to compile on Windows when on Linux this just works?

                  You have to build the Qt sql driver for MySQL by yourself for legal reasons

                  And there is no need to compile Qt by yourself. Mingw and msvc binaries are provided by the installer and the MySQL plugin compiles with both.

                  D Offline
                  D Offline
                  DiBosco
                  wrote last edited by DiBosco
                  #8

                  @Christian-Ehrlicher said in Getting QSqlError "Driver not loaded":

                  @DiBosco said in Getting QSqlError "Driver not loaded":

                  Why do you have to compile on Windows when on Linux this just works?

                  You have to build the Qt sql driver for MySQL by yourself for legal reasons

                  And there is no need to compile Qt by yourself. Mingw and msvc binaries are provided by the installer and the MySQL plugin compiles with both.

                  I'm not clear what you're saying here, Christian. I didn't compile the whole of Qt, just the mariadb libs. Or are you saying that what SGaist said wasn't quite right and there are binaries available? ie I did not have to compile mariadb libraries for Qt?

                  SGaistS Christian EhrlicherC 2 Replies Last reply
                  0
                  • D DiBosco

                    @Christian-Ehrlicher said in Getting QSqlError "Driver not loaded":

                    @DiBosco said in Getting QSqlError "Driver not loaded":

                    Why do you have to compile on Windows when on Linux this just works?

                    You have to build the Qt sql driver for MySQL by yourself for legal reasons

                    And there is no need to compile Qt by yourself. Mingw and msvc binaries are provided by the installer and the MySQL plugin compiles with both.

                    I'm not clear what you're saying here, Christian. I didn't compile the whole of Qt, just the mariadb libs. Or are you saying that what SGaist said wasn't quite right and there are binaries available? ie I did not have to compile mariadb libraries for Qt?

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote last edited by
                    #9

                    @DiBosco I think it's likely just a miscomprehension.

                    We had many people trying to build the whole of Qt in place of just building the plugins they needed following the documentation.

                    From the looks of it, you followed the right path but just had an issue with the compiler setup.

                    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
                    • D DiBosco

                      @Christian-Ehrlicher said in Getting QSqlError "Driver not loaded":

                      @DiBosco said in Getting QSqlError "Driver not loaded":

                      Why do you have to compile on Windows when on Linux this just works?

                      You have to build the Qt sql driver for MySQL by yourself for legal reasons

                      And there is no need to compile Qt by yourself. Mingw and msvc binaries are provided by the installer and the MySQL plugin compiles with both.

                      I'm not clear what you're saying here, Christian. I didn't compile the whole of Qt, just the mariadb libs. Or are you saying that what SGaist said wasn't quite right and there are binaries available? ie I did not have to compile mariadb libraries for Qt?

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote last edited by
                      #10

                      @DiBosco said in Getting QSqlError "Driver not loaded":

                      just the mariadb libs.

                      Even this is not needed - you only need to compile the Qt sql plugin. The rest is already available as binary.

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

                      D 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @DiBosco said in Getting QSqlError "Driver not loaded":

                        just the mariadb libs.

                        Even this is not needed - you only need to compile the Qt sql plugin. The rest is already available as binary.

                        D Offline
                        D Offline
                        DiBosco
                        wrote last edited by
                        #11

                        @Christian-Ehrlicher said in Getting QSqlError "Driver not loaded":

                        @DiBosco said in Getting QSqlError "Driver not loaded":

                        just the mariadb libs.

                        Even this is not needed - you only need to compile the Qt sql plugin. The rest is already available as binary.

                        Yep, that's all I did. Sounds like I described it poorly.

                        Am still intruiged as to why this has to be done on Windows, but not on Linux (or at least my Linux distro).

                        1 Reply Last reply
                        0
                        • D DiBosco has marked this topic as solved

                        • Login

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