一步步学Qt,第二天-续集:mysql driver
学习qt已经两天了,现在打算开始使用qt来连接mysql,先前在linux下面写过一个程序,不过没有mysqldirver所以连接失败了.后来才知道,原来qt连接mysql的dirver需要自己编译的.现在在windows里面.所以要自己把这个驱动给编译好了.不过还不知道如何开始编译,那就问问qt助手咯
打开qt助手,切换视图到index输入SQL Database Drivers,在右边就会出现很多的选择,我使用的是mingw,所以我点击了How to build the MySQL driver for MinGW users,
下面是内容:
How to build the MySQL driver for MinGW users
The following steps have been used successfully for WinXP SP3. In this example, Qt 4.6.2 is shown.
-
Download the following components:
- MinGW-5.1.6.exe
- mingw-utils-0.3.tar.gz
- Qt sources, e.g. qt-everywhere-opensource-src-4.6.2.zip
- mysql-5.1.35-win32.msi
- Install MinGW-5.1.6.exe in, e.g. C:\MinGW.
- Extract mingw-utils-0.3.tar.gz into, e.g. C:\MinGW.
- Add the path for MinGW-5.1.6.exe to your PATH variable, e.g. C:\MinGW\bin;
- Extract the Qt sources, (qt-everywhere-opensource-src-4.6.2.zip), into, e.g. C:\Qt.
- Add the path for the eventual Qt binary to your PATH variable, e.g. C:\Qt\4.6.2\bin;.
- Install MySQL (mysql-5.1.35-win32.msi), customizing the components. Select only the headers and libraries. Install in, e.g.C:\MySQL\MySQL51.
-
Open the DOS prompt, go to C:\MySQL\MySQL51\lib\opt, and run the following commands:
- reimp -d libmysql.lib
- dlltool -k -d libmysql.def -l libmysql.a
-
Open the DOS prompt, go to C:\Qt\4.6.2 and run the following commands:
- configure.exe -debug-and-release -platform win32-g++ -qt-sql-mysql -l mysql -I C:\MySQL\MySQL51\include -L C:\MySQL\MySQL51\lib\opt
- mingw32-make sub-src
This step takes a long time.
-
Open the DOS prompt, go to C:\Qt\4.6.2\src\plugins\sqldrivers\mysql and run the following command:
- qmake "INCLUDEPATH+=C:\MySQL\MySQL51\include" "LIBS+=-L. mysql" mysql.pro
-
Now the following libraries are ready in C:\Qt\4.6.2\plugins\sqldrivers.
- libqsqlmysql4.a
- libqsqlmysqld4.a
- qsqlmysql4.dll
- qsqlmysqld4.dll
To use the SDK and QtCreator directly, copy these libraries to your C:\Qt\...\qt\plugins\sqldrivers\, and copyC:\MySQL\MySQL51\lib\opt\libmysql.dll to your C:\Qt\...\qt\bin\.
一. QT 的opensource和sdk的区别和关系
因为在opensource版本里面貌似也有designer和assistant等等的,可能就是没有qtcreator
在这两个版本里面很多的东西都是重复的,不得不说是占地方
二. 我的mysql版本问题
我的mysql版本是5.1.74的,assistant中说的是5.1.35,不过我没有在mysql的目录下找到lib\opt这个目录...后来我猜发现,我用 了这么 久的mysql,原来我用的mysql只是一个精简版.汗!!!!
----------------------------------------------------------------------------------