cd C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\psql
qmake "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/usr/lib -lpq" psql.pro
nmake
;C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\;C:\QtSDK\Desktop\Qt\4.8.1\msvc2010\bin\
qmake -o Makefile "INCLUDEPATH+=C:\PostGreSQL\include" "LIBS+=C:\PostGreSQL\lib\ms\libpq.lib" psql.pro
QSqlDatabase: QPSQL driver not loadedQSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("localhost"); db.setDatabaseName("postgres"); db.setUserName("postgres"); db.setPassword("1"); if (db.open()) db.lastError();
QT += core gui sqlTARGET = QtPostgreSQLTEMPLATE = appSOURCES += main.cpp\ widget.cppHEADERS += widget.hFORMS += widget.uiLIBS+= -Lqsqlpsqld4
C++ (Qt)#include <QtSql>#include <QSqlDatabase>#include "widget.h"#include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("localhost"); db.setDatabaseName("postgres"); db.setUserName("postgres"); db.setPassword("1"); if (db.open()) db.lastError();} Widget::~Widget(){ delete ui;}