Getting Qt and MySQL running together and interacting properly on Windows 7 has been a real headache – much more challenging than on Ubuntu Linux the last time I tried. Without the MySQL drivers for Qt installed, you get the error
QSqlDatabase: QMYSQL driver not loaded if you attempt to use a MySQL database. Had I not found the tutorial by ieatbinary I would certainly have been defeated. One way of tackling the problem, it seems, is to get Qt and MySQL up and running independently of one another first, and then to build the MySQL plugin for Qt. Doing that avoids the need to compile all of Qt, including the MySQL driver, from source. Instead one can use the much more friendly installer. There were a few twists, though, which I will summarize here.
Step 1 – Install Qt SDK
Download the installer from http://qt.nokia.com/downloads/. Run it. Note ieatbinary’s (Step 1) point about installing source files, to ensure that you have the source files needed to compile the MySQL plugin.
Step 2 – Install MySQL
Note first that, according to ieatbinary, only 32-bit MySQL can be used to for the Qt plugin. ieatbinary’s tutorial (Step 2) tells us that we need to install the MySQL Client C API Library. I was installing MySQL as part of WampServer and did not find any way of including all of that library during installation. The only file that seemed to be required yet missing was
libmysql.lib. This can be retrieved from the ZIP archive downloadable from http://dev.mysql.com/downloads/mysql/. Two different 32-bit archives for Windows were available and only the larger of the two (I used
mysql-5.5.19-win32.zip) contained the missing file. Extract the file and copy it to the
lib directory of the existing MySQL installation (for me:
Step 3 – compile MySQL drivers for Qt
From here on, ieatbinary’s tutorial can be followed exactly. Note that I got a warning (not an error) about
unescaped backslashes during the compilation (his Step 4). Didn’t seem to matter.