Results 1 to 5 of 5

Thread: Struggling to connect to the PostgreSQL database

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Struggling to connect to the PostgreSQL database

    hi everyone, I have struggled for a long time with trying to connect my progam to a PostgreSQL database. At first I tried connecting my program to a mysql database but after a long time of trying to building the mysql driver i gave up and tried a different database (i.e. Postgresql) and still can't connect even with postgresql. code below.
    Qt Code:
    1. Server_A::Server_A(QObject *parent) :
    2. QObject(parent)
    3. {
    4. server = new QTcpServer(this);
    5. // threadPool.setMaxThreadCount(5000);
    6.  
    7. QString connectionStr = "Driver={PostgreSQL};Server=127.0.0.1;Port=5432;Database=AsicamtheDB;Uid=root;Pwd=ayaman;";
    8.  
    9. db = QSqlDatabase::addDatabase("QODBC");
    10. db.setConnectOptions();
    11. db.setDatabaseName(connectionStr);
    12.  
    13. if(db.open())
    14. {
    15. qDebug() << "connected to database" <<endl;
    16. }
    17. else
    18. {
    19. qDebug() << "Not connected" <<endl;
    20. qDebug() << db.lastError() <<endl;
    21. qDebug() << db.drivers() <<endl;
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Struggling to connect to the PostgreSQL database

    does anyone know how to resolve this

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Struggling to connect to the PostgreSQL database

    1. Can you connect with "sqlbrowser" application from Qt examples ?
    2. If you are trying to connect to PostgreSQL database, try QPSQL driver:
    Qt Code:
    1. db = QSqlDatabase::addDatabase("QPSQL");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Struggling to connect to the PostgreSQL database

    I did try PQSQL but it also doesn't work.

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Struggling to connect to the PostgreSQL database

    Ok, and what about 1) ?

Similar Threads

  1. Not receive notification issued by postgresql database
    By matteo.ceruti in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2012, 14:31
  2. Connect to database
    By seink in forum Newbie
    Replies: 12
    Last Post: 26th April 2011, 18:43
  3. Replies: 2
    Last Post: 11th February 2011, 17:53
  4. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  5. Replies: 5
    Last Post: 28th August 2006, 14:36

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.