Using mySQL with Qt under Windows is a little bit tricky.
Installation
You need to install several softwares :
- The Qt SDK, and Qt source code
- MinGW (bundled with Qt SQK)
- MinGW-utils
- MySQL
Path
To avoid path related headaches, you should create a C:/mysql directory, copy mysql headers (.h) from C:\Program Files\MySQL\MySQL Server 5.5\include/" to "C:\mysql\include\"* and copy "libmysql.lib from C:\Program Files\MySQL\MySQL Server 5.5\lib to C:\mysql\lib."
Extraction
The next step is the creation of the required shared library.
- Launch qtenv2.bat from "C:\QtSDK\Desktop\Qt\4.8.0\mingw\bin"
- Go to "C:\mysql\lib"
- Run reimp -d libmysql.lib
- Run dlltool -d libmysql.def -D libmysql.dll -l libmysql.a -k to create libmysql.a .
Make
Go to C:\QtSDK\QtSources\4.8.0\src\plugins\sqldrivers\mysql and run :
qmake "INCLUDEPATH+=C:\\mysql\\include" "LIBS+=-LC:\\mysql\\lib -lmysql" mysql.pro mingw32-make all
You should have 4 files by now :
- libqsqlmysql4.a and qsqlmysql4.dll in the release sub-folder of mysql
- libqsqlmysqld4.a and qsqlmysqld4.dll in the debug sub folder of mysql
Setup
Copy the libmysql.dll from C:\Program Files\MySQL\MySQL Server
5.5\lib to C:\QtSDK\Desktop\Qt\4.8.0\mingw\bin
Make sure that the four files that we’ve created earlier are in
C:\QtSDK\Desktop\Qt\4.8.0\mingw\plugins\sqldriver
Run !
Also, open up your current Qt project and edit your .pro file so that this line is in there: QT += sql That's it, you can now use MySQL in your Qt project !