Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PostgreSQL and Trying to connect using Qt
Forum Updated to NodeBB v4.3 + New Features

PostgreSQL and Trying to connect using Qt

Scheduled Pinned Locked Moved General and Desktop
46 Posts 8 Posters 39.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aftertaf
    wrote on 10 Feb 2014, 19:17 last edited by
    #41

    http://pastebin.com/4cpqVMiN
    folder contents

    1 Reply Last reply
    0
    • C Offline
      C Offline
      clochydd
      wrote on 10 Feb 2014, 21:27 last edited by
      #42

      Thanks for the data! I can see our "fatal" libpq-fe.h in c:\psql93_x86\include. So as a first step I suppose to test with:
      C:\QT\5.2.1\Src\qtbase\src\plugins\sqldrivers\psql>c:\Qt\5.2.1\mingw48_32\bin\qmake.exe “INCLUDEPATH+=c:\psql93_x86\include” “LIBS+=c:\psql93_x86\lib\libpq.lib” psql.pro
      I know, the backslashes are a bit unusual for Qt but it worked with my installs so give it a try! Good luck!

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aftertaf
        wrote on 12 Feb 2014, 14:34 last edited by
        #43

        i've tried on many occasions with \ and /: same result.

        The problem is obviously over my level of unkludging, and I've figured out how to use ODBC instead.

        @
        #include <QtSql>
        #include <QString>
        #include <QSqlDatabase>

        void connect_db()
        {

        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
        QStringList driversList = QSqlDatabase::drivers();
        qDebug() << "drivers list= " << driversList;
        bool bOpen(false);
        db.addDatabase("QODBC","odbcname");
        db.setHostName("localhost");
        db.setDatabaseName("dbname_in_postgres");
        db.setUserName("username");
        db.setPassword("password");
        bOpen =db.open();
        QString str=db.lastError().text();
        }@

        str remains empty :)
        and bOpen shows True for the first time in a month's trying.
        I dont need pure pg connection, using an ODBC is fine for me at this stage.
        Now for trying to make my DAO classes :)
        thanks to all for helping, sorry it didn't work out as intended, but for ODBC connections, my above code works.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Duncan
          wrote on 29 Aug 2015, 22:09 last edited by
          #44

          Hello!

          What did you put for this line:

          db.addDatabase("QODBC","odbcname");

          Not sure what to put instead of odbcname.

          Thanks!

          1 Reply Last reply
          0
          • C Offline
            C Offline
            clochydd
            wrote on 30 Aug 2015, 08:21 last edited by
            #45

            Hello Duncan,

            if you only open one database, you do not need to specify the connection name:

            db.addDatabase("QODBC");
            

            If you plan work with more connections, use a name to identify each connection:

            db.addDatabase("QODBC","myConn1");
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 30 Aug 2015, 21:30 last edited by
              #46

              Hi,

              addDatabase is a static function that returns a QSqlDatabase instance that will use the selected backend.

              So you must call it like that:
              QSqlDatabase db = QSqlDatabase::addDatabase("QODBC")

              The suggestion of @clochydd about the connection name still applies.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved