编译QT的mysql驱动 - - JavaEye技术网站

来源:百度文库 编辑:神马文学网 时间:2024/10/02 16:38:02

编译QT的mysql驱动

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代码
  1. static QTextCodec* codec(MYSQL* mysql)   
  2. {   
  3.   return QTextCodec::codecForName("GBK");   
  4. #if MYSQL_VERSION_ID >= 32321   
  5.   QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql));   
  6.   if (heuristicCodec)   
  7.     return heuristicCodec;   
  8. #endif   
  9.   return QTextCodec::codecForLocale();   
  10. }  
 

 

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