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

SQL Driver



  • I have a QML app run using the QMLViewer. When I try to use the QML db API (openDatabaseSync) I got the error...

    QSqlDatabase: QMYSQL driver not loaded

    I found the following page http://doc.qt.nokia.com/4.7/sql-driver.html#building-the-plugins-manually
    After some time, I managed to download MySQL and the developer include/library
    I successfully built and installed the QMYSQL library

    Now when I run the app it says...

    QSqlDatabase: QSQLITE driver not loaded
    QSqlDatabase: available drivers: QMYSQL3 QMYSQL
    QSQLITE driver not loaded

    Where do I set the app to use the correct plugin?

    Thanks

    Simon



  • Do you see your drivers build in Qt's plugins folder??



  • I had libqsqlite.so, libqsqlite2.so and libqsqlpsql.so in the qt/plugins/sqldrivers dir... all with old dates

    The src/plugins/sqldrivers had my newly built library libqsqlmysql.so so I have now copied this to qt/plugins/sqldrivers and did a make install that output...

    install -m 755 -p "libqsqlmysql.so" "/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so"

    ...but I still get the app error saying "QSQLITE driver not loaded"

    Simon



  • MySQL plugin is working. It seems that installing qmysql messed something with sqlite plugin. Can you provide some more info about your system (which distro, qt installed from package or source)? Maybe recompiling "qsqlite plugin":http://doc.qt.nokia.com/4.7/sql-driver.html#how-to-build-the-qsqlite-plugin will help?



  • I didn't understand, do you need qmysql or qsqlite? qmysql plugin is working: QSqlDatabase: available drivers: QMYSQL3 QMYSQL
    qsqlite is not: QSQLITE driver not loaded



  • Let's go back to the original question...

    Where do I set the app (or Qt) to use the correct plugin?

    Thanks

    Simon



  • You should add
    @
    QT += sql
    @ in your .pro file
    then in code you're using:
    @
    QSqlDatabase db;
    //...
    db = QSqlDatabase::addDatabase("QMYSQL");
    @



  • I usually put the SQL plugin in a directory called "sqldrivers", and place that directory in the same directory as the executable.

    Note that you must use the same version as your Qt libs, including debug or release version. Otherwise, the plugin will not load. It can help to change your Run Settings (from the Projects tab) and add QT_DEBUG_PLUGINS = 1 to your Run Environment. That will generate debug output for the loading of Qt plugins.


Log in to reply