Results 1 to 5 of 5

Thread: QPSQL and failed connection

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QPSQL and failed connection

    I am trying to open a database through Qt . Here is the code.
    Qt Code:
    1. inline bool createConnection()
    2. {
    3. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    4. db.setHostName("localhost");
    5. db.setDatabaseName("/home/pgdata/data1");
    6. db.setUserName("pgdata");
    7. db.setPassword("krajesh");
    8.  
    9. if (!db.open()) {
    10. QMessageBox::warning(0, QObject::tr("Database Error"),
    11. db.lastError().text());
    12. return false;
    13. }
    14. return true;
    15. }
    To copy to clipboard, switch view to plain text mode 

    it results in the error. FATAL: coulfd't coonnect to database /home/pgdata/data1.
    /home/pgdata/data1 do exists. It is a cluster of database inside it i had created one with default name pgdata. but opening it also results in same name. I can acess and query over it using psql from command prompt. Also same code with QMYSQL works well.

    quickNitin

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPSQL and failed connection

    The database name is what you specify in USE commands at the SQL prompt. What do you USE when you operate from the prompt?

  3. #3
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPSQL and failed connection

    i have used same at both places. Only difference here is i am specifying complete path.
    This i have created using createdb command.

    Exact error is:
    Qt Code:
    1. FATAL: /home/pgdata/data1 doesn't exist
    2. QPSQL :unable to connect
    To copy to clipboard, switch view to plain text mode 

    I am completely out of ideas what is the issue. Is there something i missed while installing Qt? This code which i am trying to compile is sample code from Qt book so i suppose it it bug free.
    Anyone can list out all the possibilities causing issues?

    quickNitin

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPSQL and failed connection

    But you can't specify a complete path! Maybe the code you are referring to concerns an sqlite database?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPSQL and failed connection

    Quote Originally Posted by quickNitin View Post
    I can acess and query over it using psql from command prompt.
    How do you start psql? Do you specify database name? What does \l command print?

    Most likely your database is named "pgdata".

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.