Results 1 to 2 of 2

Thread: database connection

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: database connection

    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:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QSqlDatabase>
    3. #include <QMessageBox>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    11. db.setDatabaseName("name");
    12. db.setPassword("pass");
    13. db.setHostName("localhost");
    14. db.setUserName("user");
    15. if (!db.open()) {
    16. QMessageBox::warning(0, qApp->tr("Cannot open database"),
    17. qApp->tr("Unable to establish a database connection.\n"));
    18. return false;
    19. }
    20.  
    21. return a.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by mak_user; 9th February 2011 at 05:55.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: database connection

    To save you grief next time, there is a method called 'lastError'. Use that to get more information.

Similar Threads

  1. Connection With database
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2010, 09:18
  2. Database connection
    By poporacer in forum Newbie
    Replies: 7
    Last Post: 7th September 2010, 07:49
  3. validate database connection
    By hoshy in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2009, 13:14
  4. Database connection problem
    By MarkoSan in forum Qt Programming
    Replies: 1
    Last Post: 11th September 2008, 20:18
  5. database connection
    By peace_comp in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 12:16

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.