Qt World Summit: Submit your Presentation

Problem with QMYSQL

  • Hi. I know that there's a lot of topics about it, but this is uncommon.
    Problem is that qmysql.dll loads ONLY from mingw folder and nothing helps. fighting with this 2 days and cant resolve it.
    pls help

    here's some code (setting up libs load from exe folder):
    QStringList str;

    in PRO:
    QT += sql core gui
    alt text

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    If you want the plugin to load when deploying your application, you have to respect the folder hierarchy. So you have to keep plugins/sqldrivers beside your application.

  • It is. All the folders near exe. All dlls in there.
    Used windeployqt for it. All ok if only mingw folder exists, if not - won't load and not workin'

  • Lifetime Qt Champion

    Did you also deploy MinGW's dlls ?

    One thing you can do is start your application from the command line with the QT_DEBUG_PLUGINS environnement variable set to 1.

    You'll what is happening when your plugins are getting loaded.

  • @sgaist all in there (every folder have from 1 up to 9 dlls)

    alt text

    And this is sqldrivers folder

    alt text

    Problem is that if C:\Qt\5.11.3\mingw53_32\plugins\qsqlmysql.dll exists, all ok. If I remove it - it doesn't loads from exe folder and C:\Deploy\libmysql.dll not loading too.


    But still need help.

    Problem is that driver loading before setting up default folder:

    QStringList str;

    And getting this err:

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
    my library path : ("C:\Deploy")

    Problem in database.cpp:

    #include "database.h"
    static QSqlDatabase datb = QSqlDatabase::addDatabase("QMYSQL", "datas");
    static QSqlQuery query(datb);

    static QString host = "site.host";
    static QString namedb = "name";
    static QString nameusr = "usr";
    static QString passdb = "pass";
    //db login & open
    void Database::login_db()

    Exact problem in:
    static QSqlDatabase datb = QSqlDatabase::addDatabase("QMYSQL", "datas");

    This line loading before int main(int argc, char *argv[]) and upload's qmysql from default folder of mingw

    If I remove it from there and put into login func all with loading is ok:
    alt text

    But doesn't work then my functions. How can I solve it? how to move these lines in another place:

    static QSqlDatabase datb= QSqlDatabase::addDatabase("QMYSQL", "datab");
    static QSqlQuery query(datb);

    I mean load 'em later than main.cpp

  • OR make default DIR outside of main OR in .PRO file.

  • Lifetime Qt Champion

    Are you trying to move things around in the folder where you are currently doing the application deployment ?