简体   繁体   中英

QT qmysql driver not loaded

I know there are already many topics on this forum about this problem but I did not manage to solve mine following them.

My configuration is the following:

QT Version: 5.14.2 - mscv2017_64

Compiler: mscv amd64

My problem is that my application does not load the libmysql.dll. Here is what I have done:

I opened the command line MSCV 2017 64bits provided by qt and I initialized my environment using vcvarsall.bat amd64 . Then I have built the sql driver as explained in the documentation .

Here is the result of the qmake call: 在此处输入图像描述

Then, ran nmake and nmake install and in the folder C:\Qt\5.14.2\msvc2017_64\plugins\sqldrivers , I found the following files. 在此处输入图像描述

Then I added libmysql.dll in the folder where my the exe file of my application was created. I got this file from the mysql server installation folder C:\Program Files\MySQL\MySQL Server 8.0\lib .

Then I rebuilt my application, but I still have the same error appearing, saying that the driver was not loaded. I compiled using the QT_DEBUG_PLUGINS=1 flag and I got as an output:

"The plugin 'C:/Qt/5.14.2/msvc2017_64/plugins/sqldrivers/qsqlpsqld.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" not a plugin QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/Thomas Bouchan/Documents/Personal/C++/SSVP/build-SSVP-project-Desktop_Qt_5_14_2_MSVC2017_64bit-Release/release/sqldrivers"... Cannot load library C:\Qt\5.14.2\msvc2017_64\plugins\sqldrivers\qsqlmysql.dll: The specified module could not be found. QLibraryPrivate::loadPlugin failed on "C:/Qt/5.14.2/msvc2017_64/plugins/sqldrivers/qsqlmysql.dll": "Cannot load library C:\Qt\5.14.2\msvc2017_64\plugins\sqldrivers\qsqlmysql.dll: The specified module could not be found." QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7"

From this I don't know what to do, as in the specified folder, the dll is there... Is it a question of 64 or 32 bits? Shall I build the driver with another compiler (not amd64 ?)?

I finally manage to get it working.

There was no issue with the compilation of the drivers, but the problem came from the libmysql.dll file. I don't know what happened with this dll but when I replaced it with the one downloaded the archive qsqlmysql.dll_Qt_SQL_driver_5.14.2_MSVC2017_64-Bit.zip . I only needed to replace the dll, not to use the plugins of the archive.

Opening the qsqlmysqld.dll with the dependency walker, I found out that two additional dlls files are required in libmysql.dll : LIBSSL-1_1-X64.dll and LIBCRYPTO-1_1-X64.dll . They can be found in the bin directory of the mysql server. In my case C:\Program Files\MySQL\MySQL Server 8.0\bin . Adding those files in the directory of the executable solves the problem. Thanks @king_nak for the tip!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM