qt编译mysql插件
安装MySQL,C:\Program Files (x86)\MySQL\MySQL Server 5.7,然后把include和lib文件夹拷贝到C盘,因为qmake不允许路径中有空格!!!
安装Qt源文件,即在安装Qt时勾选源文件
打开"VS2013 开发人员命令提示"
cd C:\DevelopHouse\Qt5.5.0\Src\qtbase\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=C:/MySQL/include" "LIBS+=C:/MYSQL/lib/libmysql.lib" mysql.pro
nmake
成功之后,你可以在C:\DevelopHouse\Qt5.5.0\Src\qtbase\plugins\sqldrivers找到qsqlmysql.dll和qsqlmysqld.dll
最后需要将C:\Program Files (x86)\MySQL\MySQL Server 5.7\lib\libmysql.dll文件拷贝到工程exe同目录,或者拷贝到C:\DevelopHouse\Qt5.5.0\5.5\msvc2013\bin
否则一直出现
“
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
“
官方文档说以上qmake出来的是debug版本,要是想编译release版本,需要添加"-o Makefile"
qmake "INCLUDEPATH+=C:/MySQL/include" "LIBS+=C:/MYSQL/lib/libmysql.lib" -o Makefile mysql.pro
但是我没加,也生成了qsqlmysql.dll