PDA

View Full Version : database connection



mak_user
9th February 2011, 05:55
hi,

I have trouble conneting to PostgreSQL database. With installed newest QTSDK I am working on linux platform with qt creator.

This is my code:



#include <QtGui/QApplication>
#include <QSqlDatabase>
#include <QMessageBox>


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setDatabaseName("name");
db.setPassword("pass");
db.setHostName("localhost");
db.setUserName("user");
if (!db.open()) {
QMessageBox::warning(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"));
return false;
}

return a.exec();
}


I have added sql module in .pro file.
Connection isn't established.
Is it possible that there is problem with driver, because I read that this driver is supported in QT?
Could you help me?

Thanks

Added after 15 minutes:

Don't bother, I found the problem. It was connected to postgre configuration files.

squidge
9th February 2011, 09:23
To save you grief next time, there is a method called 'lastError'. Use that to get more information.