Results 1 to 4 of 4

Thread: qt and postgresql

  1. #1
    Join Date
    Aug 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default qt and postgresql

    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...

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qt and postgresql

    What says qry.lastError() ?

  3. #3
    Join Date
    Aug 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: qt and postgresql

    ... lastError() says:

    * * * * * * * * * * * * * * * * * * * * * * * *
    QSqlError("42P01", "QPSQL: Unable to create query", "ERROR: relation \"dbo.people\" does not exist\nLINE 1: select * from dbo.people;\n^\n(42P01)")
    * * * * * * * * * * * * * * * * * * * * * * * *

    when, I have put to the name of table quotation marks \"dbo.people\" -> whole line of the application should be: if(qry.exec("select * from \"dbo.people\";")) ->
    obtained result of the application:

    * * * * * * * * * * * * * * * * * * * * * * * *
    Database is opened
    "Will"
    "Phill"
    Closing...
    * * * * * * * * * * * * * * * * * * * * * * * *

    So, problem was solved. Lesiok - Thank you so much

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qt and postgresql

    This is what differed queries in the console and in the program.

Similar Threads

  1. Qt 5.1 Postgresql Android
    By aegeelim in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 1st August 2013, 15:49
  2. Connecting Qt with PostgreSql
    By JonathanVeg in forum Newbie
    Replies: 10
    Last Post: 19th May 2012, 17:52
  3. Replies: 2
    Last Post: 11th February 2011, 17:53
  4. PostgreSQL driver
    By clusty in forum Qt Programming
    Replies: 1
    Last Post: 21st August 2008, 00:55
  5. QT4 and Postgresql driver
    By alphaqt in forum Installation and Deployment
    Replies: 6
    Last Post: 27th February 2006, 15:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.