Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSqlDatabase: QPSQL driver not loaded



  • updated: this is what I got from QT_DEBUG_PLUGINS:

    "The plugin 'D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlodbcd.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
             not a plugin
    QFactoryLoader::QFactoryLoader() looking at "D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsql.dll"
    Found metadata in lib D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsql.dll, metadata=
    {
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
                "QPSQL7",
                "QPSQL"
            ]
        },
        "archreq": 0,
        "className": "QPSQLDriverPlugin",
        "debug": false,
        "version": 331264
    }
    
    
    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() looking at "D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsqld.dll"
    Found metadata in lib D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsqld.dll, metadata=
    {
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
                "QPSQL7",
                "QPSQL"
            ]
        },
        "archreq": 1,
        "className": "QPSQLDriverPlugin",
        "debug": true,
        "version": 331264
    }
    
    
    "The plugin 'D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsqld.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
             not a plugin
    QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/nkbar/Documents/build-myRPG_alpha-Desktop_Qt_5_14_0_MSVC2017_64bit-Release/Server/release/sqldrivers" ...
    Cannot load library D:\Qt\5.14.0\msvc2017_64\plugins\sqldrivers\qsqlpsql.dll: The specified module could not be found.
    QLibraryPrivate::loadPlugin failed on "D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsql.dll" : "Cannot load library D:\\Qt\\5.14.0\\msvc2017_64\\plugins\\sqldrivers\\qsqlpsql.dll: The specified module could not be found."
    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    QFactoryLoader::QFactoryLoader() checking directory path "D:/Qt/5.14.0/msvc2017_64/plugins/accessible" ...
    QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/nkbar/Documents/build-myRPG_alpha-Desktop_Qt_5_14_0_MSVC2017_64bit-Release/Server/release/accessible" ...
    QFactoryLoader::QFactoryLoader() checking directory path "D:/Qt/5.14.0/msvc2017_64/plugins/accessiblebridge" ...
    QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/nkbar/Documents/build-myRPG_alpha-Desktop_Qt_5_14_0_MSVC2017_64bit-Release/Server/release/accessiblebridge" ...
    

    I checked "D:\Qt\5.14.0\msvc2017_64\plugins\sqldrivers\qsqlpsqld.dll" and I did found the dll which the debugger reports as missing. And I am also confused about why it complains about "'D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsql.dll' uses incompatible Qt library.

    The kit I am using is msvc2017 64bit and the postgre I downloaded is also for 64bit.


    Errors:
    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

    OS: win10 64bit
    qt: 5.14.0
    kit: msvc2017 64bit
    PostgreSQL: 12.1

    Sqlite works well, but my project just can't work with PostgreSQL.

    I followed the official instruction: https://doc.qt.io/qt-5/sql-driver.html#qpsql

    Got no error but still couldn't connect to PostgreSQL. Same error messages saying that "QPSQL driver not loaded".

    I have also tried other solutions from here and stackoverflow and reinstall my qt 4 times, No luck still. I am really frustrated now and don't know what to do.

    the .pro:

    QT += core network gui widgets sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++11
    
    QTPLUGIN += QPSQL
    QT_DEBUG_PLUGINS=1
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    #INCLUDEPATH += "D:\psql\include"
    
    #LIBS += "D:\psql\lib\libpq.lib"
    
    
    SOURCES += \
        battle.cpp \
        creature.cpp \
        player.cpp \
        server.cpp \
        servermain.cpp \
        serverwindow.cpp \
        serverworker.cpp
    
    HEADERS += \
        battle.h \
        creature.h \
        data_structs.h \
        player.h \
        server.h \
        serverwindow.h \
        serverworker.h
    
    FORMS += \
        serverwindow.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    RESOURCES += \
        resource.qrc
    
    

  • Lifetime Qt Champion

    @nkbartc said in QSqlDatabase: QPSQL driver not loaded:

    Cannot load library D:\Qt\5.14.0\msvc2017_64\plugins\sqldrivers\qsqlpsql.dll: The specified module could not be found.
    QLibraryPrivate::loadPlugin failed on "D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsql.dll" : "Cannot load library D:\Qt\5.14.0\msvc2017_64\plugins\sqldrivers\qsqlpsql.dll: The specified module could not be found."

    You're most likely missing libpq.dll in your PATH / in your folder of your executable.



  • 2.png 1.png

    I already did that. I am showing the pictures just in case if I did it wrong.



  • PostgreSQL12.1 is for 64bit. Could this cause the problem?


  • Lifetime Qt Champion

    @nkbartc said in QSqlDatabase: QPSQL driver not loaded:

    PostgreSQL12.1 is for 64bit. Could this cause the problem?

    If your app is 32 bit, then yes.

    Regards



  • @aha_1980

    OS: win10 64bit
    qt: 5.14.0
    kit: msvc2017 64bit
    PostgreSQL: 12.1

    I think I am supposed to use PostgreSQL 64bit, but I just tried with PostgreSQL 32bit. No luck.....


  • Lifetime Qt Champion

    Use dependency walker on qsqlpsql.dll to see what's missing. Maybe a msvcrt runtime



  • @Christian-Ehrlicher

    I am using kit: msvc2017 64bit.

    I suppose that I should run dependency walker on qsqlpsql.dll at
    D:\Qt\5.14.0\msvc2017_64\plugins\sqldrivers ?

    Thanks


  • Lifetime Qt Champion

    @nkbartc said in QSqlDatabase: QPSQL driver not loaded:

    I suppose that I should run dependency walker on qsqlpsql.dll at

    yes



  • 2.png

    This is what I got


  • Lifetime Qt Champion

    @nkbartc press Ok, then minimize the tree on the left side, so that only one level of dependencies is visible.

    The yellow warnings are harmless, AFAIK.


  • Lifetime Qt Champion

    Please take a look at the direct dependencies



  • @aha_1980 @Christian-Ehrlicher

    Like this? Sorry I am new to dependency walker.

    1.png


  • Lifetime Qt Champion

    @nkbartc Yes, like that.

    Unfortunately(?) that looks all good, so this library (qsqlpsql.dll) does not seem to be the problem.

    Regards


  • Moderators

    @nkbartc said in QSqlDatabase: QPSQL driver not loaded:

    I checked "D:\Qt\5.14.0\msvc2017_64\plugins\sqldrivers\qsqlpsqld.dll" and I did found the dll which the debugger reports as missing. And I am also confused about why it complains about "'D:/Qt/5.14.0/msvc2017_64/plugins/sqldrivers/qsqlpsql.dll' uses incompatible Qt library.

    On windows debug and release libraries are different binaries and can't be loaded interchangeably (unlike with linux). You probably need to build the driver with debug.


Log in to reply