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. Unable to use PostgreSQL with Qt 5.2.1
Forum Updated to NodeBB v4.3 + New Features

Unable to use PostgreSQL with Qt 5.2.1

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.8k Views 1 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.
  • B Offline
    B Offline
    bhaskar2014
    wrote on last edited by A Former User
    #1

    Even after reading related topics in the forum, and the details given in http://qt-project.org/doc/qt-5/sql-driver.html I am still unable to get a simple Qt desktop dialog application to work with PostgreSQL in Windows 7 64-bit. I am able to compile the application, but when I run it (from within Qt Creator), it is not loading the database driver and I am getting the following error (please note that I have the environment variable QT_DEBUG_PLUGINS set to 1).

    _QFactoryLoader::QFactoryLoader() looking at "C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/sqldrivers/qsqlpsqld.dll"
    Found metadata in lib C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/sqldrivers/qsqlpsqld.dll, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QPSQL7",
    "QPSQL"
    ]
    },
    "className": "QPSQLDriverPlugin",
    "debug": true,
    "version": 328193
    }

    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() looking at "C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/sqldrivers/qsqlpsqld.pdb"
    "Plugin verification data mismatch in 'C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/sqldrivers/qsqlpsqld.pdb'"
    not a plugin
    QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/testuser/qtwork/build-TestApp-Desktop_Qt_5_2_1_MSVC2012_OpenGL_64bit-Debug/debug/sqldrivers" ...
    loaded library "C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/sqldrivers/qsqlpsqld.dll"
    QLibraryPrivate::loadPlugin failed on "C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/sqldrivers/qsqlpsqld.dll" : "Cannot load library C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/sqldrivers/qsqlpsqld.dll: "
    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    QFactoryLoader::QFactoryLoader() checking directory path "C:/bin/Qt/Qt5.2.1/5.2.1/msvc2012_64_opengl/plugins/accessiblebridge" ... _

    The location of PostgreSQL library libpq.dll, C:\Program Files\PostgreSQL\9.3\bin, has been appended to the PATH variable.

    This is what I am using:

    (1) Qt Creater 3.0.1
    (2) Qt 5.2.1 MSVC2012 OpenGL 64bit
    (3) PostgreSQL 9.3 64-bit
    (4) Windows 7 64-bit
    (5) Microsoft Visual C++ Compiler 11.0

    The code snippet is quite simple, taken from the documentation pages.

    QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    //db.setHostName("localhost");
    db.setDatabaseName("mydb");
    db.setUserName("postgres");
    db.setPassword("postgres");
    bool ok = db.open();
    

    if (ok == false) {
    QSqlError error = db.lastError();
    // printing the error here
    }

    The following is my project file:
    _#-------------------------------------------------

    Project created by QtCreator 2014-03-31T09:51:40

    #-------------------------------------------------

    QT += core gui sql

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = TestApp
    TEMPLATE = app

    SOURCES += main.cpp
    dialog.cpp

    HEADERS += dialog.h

    FORMS += dialog.ui

    LIBS += -LC:\Program Files\PostgreSQL\9.3\lib
    LIBS += -llibpq_

    Any help or hint to resolve this would be highly appreciated.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Check that the PATH environment variable in the Run part of the Project panel also contains the path to the PostgreSQL dll

      Hope it helps

      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
      • B Offline
        B Offline
        bhaskar2014
        wrote on last edited by
        #3

        Hello SGalst, thank you for the reply.

        Yes the path to PostgreSQL dll, C:\Program Files\PostgreSQL\9.3\bin, is already appended to the PATH env. variable in the Run part of the Project panel.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bhaskar2014
          wrote on last edited by
          #4

          Solved after using Dependency Walker to look at qsqlpsqld.dll.

          1 Reply Last reply
          0
          • Think7T Offline
            Think7T Offline
            Think7
            wrote on last edited by
            #5

            This also happens on 5.7.

            I've created an issue and a resolution here:

            https://bugreports.qt.io/browse/QTBUG-55077

            TL;DR = Add the location of the LIBPQ.DLL client library to your windows PATH envar.

            1 Reply Last reply
            1

            • Login

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