Hi everybody!
I have been trying to solve strange problem with "SELECT" command from qt application. I use postgresql server (9.3.14 on kubuntu). There is no troubles to use "SELECT" command from psql nor pgAdmin III but my qt application with "exec()" method gives only "false".
The SELECT example from psql:
* * * * * * * * * * * * * * * * * * * * * * * *
test=# select * from "dbo.people";
ID | FirstName | LastName
----+-----------+----------
1 | Will | Hope
2 | Phill | Smith
(2 rows)
* * * * * * * * * * * * * * * * * * * * * * * *
My application:
* * * * * * * * * * * * * * * * * * * * * * * *
#include <QCoreApplication>
#include <QtSql>
#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setDatabaseName("test");
db.setPort(5432);
bool ok = db.open();
if(ok != true)
{
qDebug() << "Database is not opened";
}
else
{
qDebug() << "Database is opened";
QSqlQuery qry;
if(qry.exec("select * from dbo.people;"))
{
while(qry.next())
{
qDebug() << qry.value(0).toString();
}
}
else
{
qDebug() << "Connection Failed!" << db.lastError().text();
}
qDebug() << "Closing...";
db.close();
}
return a.exec();
}
* * * * * * * * * * * * * * * * * * * * * * * *
Finally I got the answer in XTerm:
* * * * * * * * * * * * * * * * * * * * * * * *
Database is opened
Connection Failed
Closing...
* * * * * * * * * * * * * * * * * * * * * * * *
After a few days I have no idea how to solve it...
Bookmarks