Qt on windows does not compile with MySQL support out of the box. If you’re unsure how to compile Qt on Windows with Visual Studio take a look at my other post on how to create a Qt Shadow build with Visual Studio. Based on the setup explained there, you have to first download the MySQL server. I recommend using the zipped pre-compiled binary releases (such as mysql-5.x.x-win32.zip
), otherwise you’ll have the burden to compile MySQL yourself too. Decompress this into a directory of your choice, e.g. D:\dev\mysql
.
Now, when you configure your Qt build, add the appropriate options shown coloured below:
configure -ltcg -opensource -mp -qt-sql-mysql -I D:\dev\mysql\include -L D:\dev\mysql\lib -l libmysql
You should see the Qt configuration output mentioning MySQL support. Follow the subsequent steps outlined in my [intlink id=”54″ type=”post”]other post[/intlink] to compile Qt and if everything is setup properly, you will end up with a Qt version that supports MySQL via QSql.
Software used
(versions here are updated each time I update the toolset and libraries)
- Microsoft Visual Studio 2010 Ultimate Edition
- Nokia Qt [v4.7.2, v4.8.0, v4.8.1]
- MySQL [v5.5.10, v5.5.22, v5.5.24]