我已經編譯好的qt mysql驅動在 http://download.csdn.net/source/2794174
這個編譯的過程如下:
首先安裝QT creator,我用的版本是2010.05,並且已經整合了mingw32
1.下載mysql的sdk並安裝,http://www.mysql.com/downloads/connector/cpp/
2.在c盤下,建立C:/mysql/MySQL51目錄,後將C:/Program Files/MySQL/MySQL Connector C 6.0.2下的include和lib目錄拷貝過去。
3.下載一個DEV-CPP,安裝後把c:/dev-cpp/bin加入到系統內容變數的path中
4.下載動態庫格式轉換工具http://www.qtcn.org/download/mingw-utils-0.3.tar.gz
,把reimp.exe解壓到dev-cpp/bin目錄下
5.到cmd命令列下,執行 cd C:/mysql/MySQL51/opt/,進入mysql的庫目錄下,執行reimp -d libmysql.lib將其轉換為libmysql.def,再執行dlltool -k -d libmysql.def -l libmysql.a
6.單擊螢幕左下角[開始] 按鈕,進入“Qt SDK by Nokia v2010.05 (open source)”,選擇“Qt Command Prompt”,進入qt內建的命令列,執行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,之後是更漫長的等待...
7.完成後,進入C:/Qt/2010.05/qt/src/plugins/sqldrivers/mysql,輸入qmake -o Makefile "INCLUDEPATH+=C:/MYSQL/MYSQL51/INCLUDE" "LIBS+=C:/MYSQL/MYSQL51/LIB/OPT/LIBMYSQL.a" mysql.pro
8.輸入mingw32-make
9.編譯完成後在C:/Qt/2010.05/qt/plugins/sqldrivers/就會多出
- libqsqlmysql4.a
- libqsqlmysqld4.a
- qsqlmysql4.dll
- qsqlmysqld4.dll
編譯就成功了。另外還要把C:/MySQL/MySQL51/lib/opt/libmysql.DLL 檔案拷貝的c:/qt/2010.05/qt/bin下面。然後就可以寫qt串連mysql的程式了,但是這時候也有個問題,就是編譯會報錯找不到mysql.h,我用的方法是把c:/mysql/mysql51/include中的所有檔案,拷貝到了C:/Qt/2010.05/qt/include/QtSql
參考:http://student.csdn.net/space.php?uid=32341&do=blog&id=10663