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函数,修改后为:
4. 执行
cd %QTDIR%/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
这时我们需要将C:/MySQL/bin 目录下的libmySQL.dll 文件复制到我们Qt Creator 安装目录下的qt/bin 目录中。