Building SQL Database Drivers for Qt

Each time I upgrade the Qt library on Windows, I have to remember how to build the SQL database drivers using MinGW.  In particular, I need Qt to be able to connect to PostgreSQL and MySQL databases.  By default, on Windows, those drivers are not built.

Instead of searching the Qt website each time, I've decided to write down how I do it.  May be it will be helpful to someone else.

Note : For both databases, you need the client libraries and headers installed.  You also need to have Mingw in your path (ex: C:\Qt\2010.02.1\mingw\bin)

 

MySQL

Assuming that MySQL is installed under c:\mysql :

 

 cd %QTDIR%\src\plugins\sqldrivers\mysql
 qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\lib\opt\libmysql.lib" mysql.pro
 make

PostgreSQL

Assuming that PostgreSQL is installed under c:\psql :

 cd %QTDIR%\src\plugins\sqldrivers\psql
 qmake "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\libpq.lib" psql.pro
 make


That's it.  You should now be able to build Qt applications that could connect to MySQL or PostgreSQL.  If not, leave a comment below.