在Windows下面利用QT开发数据库应用,如MYSQL,首先,我们必须利用源码编译MYSQL驱动库;
1)安装qt-sdk-win-opensource-2010.02.1.exe
此时,QT安装了QT Creator,假定目录为:
E:/Qt/2010.02.1/,可以选择安装MingW;
此时,E:/Qt/2010.02.1/QT为Qt库的安装位置;
2)安装MySQl,假定目录为:
include 路径为:D:/MySQL/MySQL Server 5.0/include
lib路径为:D:/MySQL/MySQL Server 5.0/lib/opt
由于两路径还有空格;拷贝至C:/mysql文件夹下;
3)将E:/Qt/2010.02.1/QT/bin 和MINGW/bin加入到PATH中;
4)cd E:/Qt/2010.02.1/qt/src/plugins/sqldrivers/mysql文件夹
运行:
E:/Qt/2010.02.1/qt/src/plugins/sqldrivers/mysql>qmake -o Makefile "INCLUDEPA
TH+=C:/mysql/INCLUDE" "LIBS+=C:/mysql/lib/opt/libmysql.lib" mysql.pro
nmake
在E:/Qt/2010.02.1/qt/plugins/sqldrivers下生成MYSQL的驱动;
编写数据库访问代码:
访问成功;