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

Installing Qt with PostgreSQL drivers macOS m1



  • Hello all

    I am trying to install Qt with PostgreSQL sql driver, and have tried almost everything to have the psql drivers before installing Qt.

    I have tried installing Postgres via homebrew, via the official installer and the Postgres.app and libpq, libpqxx via homebrew but neither the offline or online installer detects Postgres.

    Has anyone managed to do this?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Start your application with the QT_DEBUG_PLUGINS environment variable set to 1. It will show you a dump of what happens when the plugins are getting loaded and why it failed.



  • @SGaist said in Installing Qt with PostgreSQL drivers macOS m1:

    QT_DEBUG_PLUGINS

    Thank you so much for your reply.

    Unfortunately I am not really familiar with the output.

    QFactoryLoader::QFactoryLoader() checking directory path "/Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers" ...
    QFactoryLoader::QFactoryLoader() looking at "/Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlite.dylib"
    Found metadata in lib /Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlite.dylib, metadata=
    {
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
                "QSQLITE"
            ]
        },
        "archreq": 0,
        "className": "QSQLiteDriverPlugin",
        "debug": false,
        "version": 331520
    }
    
    
    Got keys from plugin meta data ("QSQLITE")
    QFactoryLoader::QFactoryLoader() looking at "/Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlodbc.dylib"
    Found metadata in lib /Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlodbc.dylib, metadata=
    {
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
                "QODBC3",
                "QODBC"
            ]
        },
        "archreq": 0,
        "className": "QODBCDriverPlugin",
        "debug": false,
        "version": 331520
    }
    
    
    Got keys from plugin meta data ("QODBC3", "QODBC")
    QFactoryLoader::QFactoryLoader() looking at "/Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib"
    Found metadata in lib /Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib, metadata=
    {
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
                "QPSQL7",
                "QPSQL"
            ]
        },
        "archreq": 0,
        "className": "QPSQLDriverPlugin",
        "debug": false,
        "version": 331520
    }
    
    
    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/USERNAME/src/audioManager/cmake-build-debug/sqldrivers" ...
    Cannot load library /Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib: (dlopen(/Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib, 133): Library not loaded: /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib
      Referenced from: /Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib
      Reason: image not found)
    QLibraryPrivate::loadPlugin failed on "/Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib" : "Cannot load library /Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib: (dlopen(/Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib, 133): Library not loaded: /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib\n  Referenced from: /Users/USERNAME/Qt/5.15.2/clang_64/plugins/sqldrivers/libqsqlpsql.dylib\n  Reason: image not found)"
    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    "Driver not loaded Driver not loaded"
    

    From what I collect, it says it cannot find the driver and it cannot find the driver because when I installed qt, even though I had installed Postgres and qt-postgres (from brew), it could not find the dev libs. Does that make sense?


  • Lifetime Qt Champion

    The PSQL driver is found that is not the issue.

    What happens here is that the driver has been built using libpq coming with the Postgres App which is the official package provided by the project to get a quick and easy installation of PostgreSQL on macOS.

    See this path

    @kaptsea said in Installing Qt with PostgreSQL drivers macOS m1:

    /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib

    Where did brew install PostgreSQL ?
    Can you locate the libpq library in there ?
    If you find it, then what you can do is use install_name_tool to update that path to match the one from the libpq dylib you have on your machine.


Log in to reply