Important: Please read the 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
    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?



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

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

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

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

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


  • 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": 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?



  • 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