Using MySQL with Qt (QMYSQL module)
The Qt documentation states:
How to Build the QMYSQL Plugin on Windows
You need to get the MySQL installation files. Run SETUP.EXE and choose “Custom Install”. Install the “Libs & Include Files” Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL):
cd %QTDIR%\src\plugins\sqldrivers\mysql qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro nmake
If you are not using a Microsoft compiler, replace nmake with make in the line above.
If there are spaces in your include path, it won’t work. The easiest solution for me was to use the 8.3 directory names for all directories containing spaces. You can find out the 8.3 name of a directory by using the dir /x command, for instance:
dir /x "C:\Program Files"
So your qmake command could look something like this:
qmake -win32 "INCLUDEPATH+=C:\Progra~1\MySQL\MYSQLS~1.1\include" "LIBS+=C:\Progra~1\MySQL\MYSQLS~1.1\lib\opt\libmysql.lib" mysql.pro
Then just run nmake, it should work.
In case you get the nmake error that winver.h is not found, you may copy it from the VS PlatformSDK directory, e.g.:
If you get more errors, like cl.exe is missing mspdb80.dll go to
t0 set the needed paths.
Warning: vcvarsall will not set the environment permanently, at least it doesn’t do that for me. So call it from the current console session right before you execute nmake.