[英]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 QT 版本:5.14.2 - mscv2017_64
Compiler: mscv amd64编译器:mscv amd64
My problem is that my application does not load the libmysql.dll.我的问题是我的应用程序没有加载 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
.我打开了 qt 提供的命令行 MSCV 2017 64bits 并使用
vcvarsall.bat amd64
初始化了我的环境。 Then I have built the sql driver as explained in the documentation .然后我按照文档中的说明构建了 sql 驱动程序。
Here is the result of the qmake call:这是 qmake 调用的结果:
Then, ran nmake
and nmake install
and in the folder C:\Qt\5.14.2\msvc2017_64\plugins\sqldrivers
, I found the following files.然后,运行
nmake
和nmake install
并在文件夹C:\Qt\5.14.2\msvc2017_64\plugins\sqldrivers
中找到以下文件。
Then I added libmysql.dll
in the folder where my the exe file of my application was created.然后我在创建应用程序的 exe 文件的文件夹中添加了
libmysql.dll
。 I got this file from the mysql server installation folder C:\Program Files\MySQL\MySQL Server 8.0\lib
.我从 mysql 服务器安装文件夹
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:我使用
QT_DEBUG_PLUGINS=1
标志进行编译,得到了 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.
“插件 'C:/Qt/5.14.2/msvc2017_64/plugins/sqldrivers/qsqlpsqld.dll' 使用不兼容的 Qt 库。(不能混合调试和发布库。)”不是插件 QFactoryLoader::QFactoryLoader() 检查目录路径“C:/Users/Thomas Bouchan/Documents/Personal/C++/SSVP/build-SSVP-project-Desktop_Qt_5_14_2_MSVC2017_64bit-Release/release/sqldrivers”... 无法加载库 C:\Qt\5.14.2\msvc2017_64\plugins sqldrivers\qsqlmysql.dll:找不到指定的模块。 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."
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:指定的模块无法找到。” QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7"
QSqlDatabase:未加载 QMYSQL 驱动程序 QSqlDatabase:可用驱动程序: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?从这里我不知道该怎么办,因为在指定的文件夹中,dll 在那里......是64位还是32位的问题? Shall I build the driver with another compiler (not
amd64
?)?我应该用另一个编译器(不是
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.驱动程序的编译没有问题,但问题来自
libmysql.dll
文件。 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 .我不知道这个 dll 发生了什么,但是当我用下载的存档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.
我只需要替换 dll,而不是使用存档的插件。
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
. 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.它们可以在 mysql 服务器的 bin 目录中找到。 In my case
C:\Program Files\MySQL\MySQL Server 8.0\bin
.在我的情况下
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!
感谢@king_nak 的提示!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.