根据Qt助手SQL Database Drivers 章节内容安装postgreSQL 8.4 for windows后,按照Qt官方的文档

How to Build the QPSQL Plugin on Windows

Install the appropriate PostgreSQL developer libraries for your compiler. Assuming that PostgreSQL was installed in C:\psql, build the plugin as follows:

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

设置相对应的pgsql的目录,然后直接打开QtCreator打开psql.pro项目编译就成功生成相应的dll (D:\Qt\2010.03\qt\plugins\sqldrivers), 但此时还是不能正常使用该驱动,原因是pgsql的库未加入到PATH里面。

设置好后
QApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
return a.exec();


相应的名字为 "QPSQL7","QPSQL"


参考文章 http://www.qtcentre.org/wiki/index.php?title=Building_the_QPSQL_plugin_on_Windows_using_MinGW