1. 安装mysql的时候一定要安装"Libs & Include Files"的开发者模块
2. 设置环境变量
PATH
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Qt\4.5.0\bin;C:\Program Files\Microsoft Visual Studio 8\VC\bin;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE
分别是以下几个目录:
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
C:\Program Files\Microsoft SQL Server\90\Tools\binn\;
C:\Qt\4.5.0\bin;
C:\Program Files\Microsoft Visual Studio 8\VC\bin;
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE
INCLUDE
C:\Program Files\Microsoft Visual Studio 8\VC\include;C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\INCLUDE;C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include;C:\Qt\4.5.0\include\QtCore;C:\Program Files\MySQL\MySQL Server 5.1\include
分别是以下几个目录
C:\Program Files\Microsoft Visual Studio 8\VC\include;
C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\INCLUDE;
C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;
C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include;
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include;
C:\Qt\4.5.0\include;
C:\Program Files\MySQL\MySQL Server 5.1\include
LIBPATH
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB
分别是以下几个目录
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;
C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB
LIB
C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;C:\Program Files\MySQL\MySQL Server 5.1\lib\debug;C:\Program Files\MySQL\MySQL Server 5.1\lib\opt
分别是以下几个目录:
C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB;
C:\Program Files\Microsoft Visual Studio 8\VC\LIB;
C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib;
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;
C:\Program Files\MySQL\MySQL Server 5.1\lib\debug;
C:\Program Files\MySQL\MySQL Server 5.1\lib\opt
3. 为防止中文乱码,修改mysql驱动的源代码
修改codec函数,修改后为:
Cpp代码
staticQTextCodec* codec(MYSQL* mysql)
{
returnQTextCodec::codecForName("GBK");
#if MYSQL_VERSION_ID >= 32321
QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql));
if(heuristicCodec)
returnheuristicCodec;
#endif
returnQTextCodec::codecForLocale();
}
static QTextCodec* codec(MYSQL* mysql)
{
return QTextCodec::codecForName("GBK");
#if MYSQL_VERSION_ID >= 32321
QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql));
if (heuristicCodec)
return heuristicCodec;
#endif
return QTextCodec::codecForLocale();
}
4. 执行
cd C:\Qt\4.5.0\src\plugins\sqldrivers\mysql
qmake -o Makefile mysql.pro
nmake
如果成功就会在C:\Qt\4.5.0\plugins\sqldrivers目录下产生一系列文件:
qsqlmysql4.dll
qsqlmysql4.exp
qsqlmysql4.lib
qsqlmysqld4.dll
qsqlmysqld4.exp
qsqlmysqld4.ilk
qsqlmysqld4.lib
qsqlmysqld4.pdb