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

Qt connection to MySQL database not working (macOS MOJAVE)



  • Hello guys, hope you're all well
    I have MySQL 5.7 with MAMP installed and Qt 5.12.0.
    I'm not able to connect my Qt application with the Mysql server.

    I've run these 2 following commands:
    1.
    Macs-MacBook-Pro:/ macbook$ find / -iname libmysqlclient.18.dylib
    /usr/local/lib/libmysqlclient.18.dylib
    /usr/local/Cellar/mysql-connector-c/6.1.11/lib/libmysqlclient.18.dylib

    Macs-MacBook-Pro:/ macbook$ install_name_tool -change libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib /Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
    Macs-MacBook-Pro:/ macbook$

    I also tried to follow the following solution: https://forum.qt.io/topic/99776/problem-with-mysql-driver-on-mac

    Here is a screenshot of my "Run Environnement"

    0_1550857475891_Capture d’écran 2019-02-22 à 5.39.31 PM.png

    I've started my application with QT_DEBUG_PLUGINS and this is a part of the output.

    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/macbook/Projets_C++/Projet_Qt/build-Projet_final-Desktop_Qt_5_12_0_clang_64bit-Debug/Projet_final.app/Contents/MacOS/sqldrivers" ...
    Cannot load library /Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
    Referenced from: /Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
    Reason: image not found)
    QLibraryPrivate::loadPlugin failed on "/Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n Referenced from: /Users/macbook/Qt/5.12.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n Reason: image not found)"
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/macbook/Qt/5.12.0/clang_64/plugins/iconengines" ...
    QFactoryLoader::QFactoryLoader() looking at "/Users/macbook/Qt/5.12.0/clang_64/plugins/iconengines/libqsvgicon.dylib"
    Found metadata in lib /Users/macbook/Qt/5.12.0/clang_64/plugins/iconengines/libqsvgicon.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QIconEngineFactoryInterface",
    "MetaData": {
    "Keys": [
    "svg",
    "svgz",
    "svg.gz"
    ]
    },
    "archreq": 0,
    "className": "QSvgIconPlugin",
    "debug": false,
    "version": 330752
    }

    Got keys from plugin meta data ("svg", "svgz", "svg.gz")
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/macbook/Projets_C++/Projet_Qt/build-Projet_final-Desktop_Qt_5_12_0_clang_64bit-Debug/Projet_final.app/Contents/MacOS/iconengines" ...
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

    Thanks in advance.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From the looks of it, your install_name_tool call is wrong. You have to path the exact same path as first argument as the one you find from the otool call.


Log in to reply