Source: Qmysql driver not loaded : r/QtFramework
CASE #1: you execute QSqlDatabase::addDatabase(“QMYSQL”), but you get the following error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
It means that “qsqlmysql.dll” (a plugin for Qt platform) was not found.
The fix is to define the environment variable QT_PLUGIN_PATH and put qsqlmysql.dll into %QT_PLUGIN_PATH%/sqldrivers/
Note, qsqlmysql.dll must be built using MSVC (32-bit in your case), not MinGW, if you use MSVC compiler in Qt itself.
An alternative fix is to put qsqlmysql.dll into Qt/6.*.*/msvc2019_*/plugins/sqldrivers/,
or if you use PySide6, into one of
CASE #2: you execute QSqlDatabase::addDatabase(“QMYSQL”), but you get the following error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QMARIADB QMYSQL QSQLITE QODBC QPSQL
It means that “qsqlmysql.dll” was found, but its dependencies were not.
The “qsqlmysql.dll” additionally requires 3 DLLs: libmysql.dll, libssl*.dll, libcrypto*.dll (names of the last two vary for 32-/64-bit architectures).
These DLLs must be located in %PATH% or in current directory.
If you place the DLL near your C++ program or (in case of PySide6) near your python script, this won’t work if current working directory is different from application’s location.