problem of mysql driver:
qt has built in mysql driver, but the version of dll file is mismatched, so the dll file has to be recompiled to generate
in .pro file:QT += sql
my qt is
qt-opensource-windows-x86-mingw491_opengl-5.4.0-rc.exe
- install the latest connector at official website :https://dev.mysql.com/downloads/connector/c/
download :mysql-connector-c-6.1.11-win32 (choose 32 bit, if your qt is 32 bit, this can run in 64 bits machine)
I install the connector at C:\mysql\msyql_connector
2.driver of mysql in qt :C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\plugins\sqldrivers\mysql
-
open Qt5.4 console:C:\Users\fangl\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Qt 5.4.0\5.4\MinGW 4.9 (32-bit)\Qt 5.4 for Desktop (MinGW 4.9 32 bit)
-
in qt concole
>> cd C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\plugins\sqldrivers\mysql
>> qmake "INCLUDEPATH+=C:\mysql\msyql_connector\include" "LIBS+=C:\mysql\msyql_connector\lib\libmysql.lib" -o Makefile mysql.pro
you can change to your own path
>> mingw32-make
wait fo rfinish of compilation
- in C:\Qt\Qt5.4.0\5.4\Src\qtbase\plugins\sqldrivers
has already generate the latest mysql driver file
copy the whole sqldrivers directory to replace C:\Qt\Qt5.4.0\5.4\mingw491_32\plugins\sqldrivers
copy the downloaded connector dll file from D:\mysql-connector-c-6.1.11-win32\lib\libmysql.dll
to
C:\Qt\Qt5.4.0\5.4\mingw491_32\bin\
END! :)
reference:
author:偷风筝的人_
link:https://www.jianshu.com/p/a55c51f71c0c
网友评论