Building QMYSQL / MARIADB with Qt 6.3.0
-
Hi all, been having a nightmare with trying to build QMYSQL/MariaDB drivers for Qt6. I read through the documentation (https://doc.qt.io/qt-6/sql-driver.html#qmysql) and found all the required files within my installation of the MariaDB connecter, relative to my Qt version (running 64bit).
Afterwards, I followed the instructions and assumed that I was to build the plugin in the directory of my Qt 6.3.0 bin folders (for mingw_64 or msvc2019), which left me with an error.'"cmake"' is not recognized as an internal or external command, operable program or batch file.
I assumed that Qt 6.3.0 didn't come with Qt-cmake for whatever reason, so I opted to install WSL and try and download the QMYSQL drivers via package at https://ubuntu.pkgs.org/22.04/ubuntu-universe-amd64/libqt6sql6-mysql_6.2.4+dfsg-2ubuntu1_amd64.deb.html instead as a work-around.
This worked, but I have no clue where the plugin is now located on my windows machine and where to place it, even if I did manage to find where they had been placed.Is there any possible way I could acquire the qt-cmake.exe as it hasn't come with the version? Or does 6.3.0 not support this plugin yet?
-
Something I didn't realise, when looking at Qt Creator, I was using a Replacement for Qt 6.2.3. This, along with receiving .dll files from a friend managed to output
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQL
When running my program using QMYSQL. Code below is how I'm designating QMYSQL as the driver used.
QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL"); database.setHostName("localhost"); database.setDatabaseName("database_name"); database.setUserName("username"); database.setPassword("password");
So this means that either something is wrong with how I'm trying to load the QMYSQL driver, or there's something beyond this that could be preventing the driver from being loaded. Any ideas on what this could be?
-
Hi and welcome to devnet,
If memory serves well, the online installer also provides the option to install cmake.
As for the loading issue, start your application with the QT_DEBUG_PLUGINS environment variable set to 1. You can do that in the Run part of the Project panel.
-
Sorry, I have done that correct, I just found it.
That doesn't seem to have done anything, in fact it was already set towards 1 when I checked. The online installer also seems to have CMake 3.21.1 64-bit showing as installed under Developer and Designer Tools. -
If the environment variable is properly defined, you should have a dump of information about the plugins being loaded and why they failed.
-
@SGaist
I'm assuming this would be{ "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL", "QMARIADB" ] }, "archlevel": 0, "className": "QMYSQLDriverPlugin", "debug": true, "version": 393728 } qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QMYSQL", "QMARIADB") qt.core.plugin.factoryloader: looking at "C:/Qt/6.3.0/mingw_64/plugins/sqldrivers/qsqlodbc.dll" qt.core.plugin.loader: Found metadata in lib C:/Qt/6.3.0/mingw_64/plugins/sqldrivers/qsqlodbc.dll, metadata=
Along with this line.
qt.core.library: "C:/Qt/6.3.0/mingw_64/plugins/sqldrivers/qsqlmysql.dll" cannot load: Cannot load library C:\Qt\6.3.0\mingw_64\plugins\sqldrivers\qsqlmysql.dll: The specified module could not be found. qt.core.plugin.loader: QLibraryPrivate::loadPlugin failed on "C:/Qt/6.3.0/mingw_64/plugins/sqldrivers/qsqlmysql.dll" : "Cannot load library C:\\Qt\\6.3.0\\mingw_64\\plugins\\sqldrivers\\qsqlmysql.dll: The specified module could not be found."
Since that's the sqldriver folder, I checked. Results are above. I can only guess that there's a missing .debug file, or that the .dll is incompatible with Qt for some reason. -
Maybe a silly question but are you sure that the dll you have now is from the correct compiler ?
-
You do not have to rebuild everything. Just the plugin.
-
@SGaist
I'm not entirely sure how to build it based on the documentation. I have the files for MariaDB location in the right folders when it comes to the .lib, .dll and .h files. Problem is that I'm not sure where I should be for building the plugins when it comes to the command prompt.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_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib" cmake --build . cmake --install .
I'm not entirely sure where I should be located within my file structure to build the plugins, inside of the Qt 6.3.0 folder? The bin folder of the Qt 6.3.0 folder perhaps? qt-cmake doesn't seem to be recgonised as a command, so I assume it's located somewhere inside of the Qt folder.
'qt-cmake' is not recognized as an internal or external command, operable program or batch file.
I also do not know what Ninja refers to within the command. Do I need to install this too?
-
Try with just cmake in place of qt-cmake.
As for Ninja, it's also available through the installer.
-
@SGaist
Since I'm using and building for MariaDBqt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib"
The DMySQL and DMySQL_LIBRARY should probably be replaced with DMariaDB or some equivalent, correct? The locations will change, but obviously those are where I've installed the relevant files.
-
From memory, no, MariaDB is a drop in replacement so it would not make sense to complicate the build system for that.