Getting QSqlError "Driver not loaded"
-
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 QPSQLAs 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 += targetAnyone able to give me a nudge here as to what I am missing?
Thanks!
-
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
-
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
@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-sqldriversWhat 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-winx64Is 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.
-
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 beC:/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.
platformis what you have afterC:/Qt6/6.10.2It will create a plugin that will use the library you supplied.
-
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!
-
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!
@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 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() -
@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.
@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-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?
@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.
-
@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?
@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.
-
@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.
@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).
-
D DiBosco has marked this topic as solved