Qt Ubuntu QSqlDatabase: QMYSQL driver not loaded



  • i use documentation
    https://forum.qt.io/topic/59449/qsqldatabase-qmysql-driver-not-loaded-build-mysql-plugin/2
    http://doc.qt.io/qt-5/sql-driver.html
    alt text

    but i have exception when open connect, why?

    "2018-01-18 02:04:52.567 WRN default: QSqlDatabase: QMYSQL driver not loaded
    2018-01-18 02:04:52.567 WRN default: QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7"


  • Moderators

    @magalss Can you post the output of this command:

    ldd /usr/lib/i386-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.sh
    


  • alt text


  • Moderators

    @magalss It looks like libqsqlmysql.so takes libmysqlclient.so from /usr/lib/... not from /usr/local/lib.
    If you want to use the one from /usr/local/lib you will need to add the path to LD_LIBRARY_PATH
    You can try to set QT_DEBUG_PLUGINS=1 before starting your app - you then should see some debug output which can help to find the issue (see http://doc.qt.io/qt-5/debug.html).



  • @jsulm said in Qt Ubuntu QSqlDatabase: QMYSQL driver not loaded:

    LD_LIBRARY_PATH

    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/Qt/5.5/gcc/plugins/platforms" ...
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/platforms/libqlinuxfb.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/platforms/libqlinuxfb.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
        "MetaData": {
            "Keys": [
                "linuxfb"
            ]
        },
        "className": "QLinuxFbIntegrationPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("linuxfb")
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/platforms/libqminimal.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/platforms/libqminimal.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
        "MetaData": {
            "Keys": [
                "minimal"
            ]
        },
        "className": "QMinimalIntegrationPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("minimal")
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/platforms/libqoffscreen.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/platforms/libqoffscreen.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
        "MetaData": {
            "Keys": [
                "offscreen"
            ]
        },
        "className": "QOffscreenIntegrationPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("offscreen")
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/platforms/libqxcb.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/platforms/libqxcb.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
        "MetaData": {
            "Keys": [
                "xcb"
            ]
        },
        "className": "QXcbIntegrationPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("xcb")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/ProjectTerminal/build-PaymentTerminal-Desktop-Debug/platforms" ...
    loaded library "/home/max/Qt/5.5/gcc/plugins/platforms/libqxcb.so"
    loaded library "Xcursor"
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/Qt/5.5/gcc/plugins/xcbglintegrations" ...
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/xcbglintegrations/libqxcb-glx-integration.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/xcbglintegrations/libqxcb-glx-integration.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.Xcb.QXcbGlIntegrationFactoryInterface.5.5",
        "MetaData": {
            "Keys": [
                "xcb_glx"
            ]
        },
        "className": "QXcbGlxIntegrationPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("xcb_glx")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/ProjectTerminal/build-PaymentTerminal-Desktop-Debug/xcbglintegrations" ...
    loaded library "/home/max/Qt/5.5/gcc/plugins/xcbglintegrations/libqxcb-glx-integration.so"
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/Qt/5.5/gcc/plugins/platformthemes" ...
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/platformthemes/libqgtk2.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/platformthemes/libqgtk2.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1",
        "MetaData": {
            "Keys": [
                "gtk2"
            ]
        },
        "className": "QGtk2ThemePlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("gtk2")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/ProjectTerminal/build-PaymentTerminal-Desktop-Debug/platformthemes" ...
    loaded library "/home/max/Qt/5.5/gcc/plugins/platformthemes/libqgtk2.so"
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/Qt/5.5/gcc/plugins/platforminputcontexts" ...
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface.5.1",
        "MetaData": {
            "Keys": [
                "compose"
            ]
        },
        "className": "QComposePlatformInputContextPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("compose")
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so, metadata=
    {
        "IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface.5.1",
        "MetaData": {
            "Keys": [
                "ibus"
            ]
        },
        "className": "QIbusPlatformInputContextPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("ibus")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/ProjectTerminal/build-PaymentTerminal-Desktop-Debug/platforminputcontexts" ...
    loaded library "/home/max/Qt/5.5/gcc/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so"
    loaded library "libdbus-1"
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/Qt/5.5/gcc/plugins/styles" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/ProjectTerminal/build-PaymentTerminal-Desktop-Debug/styles" ...
    loaded library "gtk-x11-2.0"
    loaded library "gnomeui-2"
    loaded library "gnomevfs-2"
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/Qt/5.5/gcc/plugins/iconengines" ...
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/iconengines/libqsvgicon.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/iconengines/libqsvgicon.so, metadata=
    {
        "IID": "org.qt-project.Qt.QIconEngineFactoryInterface",
        "MetaData": {
            "Keys": [
                "svg",
                "svgz",
                "svg.gz"
            ]
        },
        "className": "QSvgIconPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("svg", "svgz", "svg.gz")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/ProjectTerminal/build-PaymentTerminal-Desktop-Debug/iconengines" ...
    
    


  • my code

    #include "mainwindow.h"
    #include <QApplication>
    #include <QFile>
    #include <QDir>
    #include <QScopedPointer>
    #include <QTextStream>
    #include <QDateTime>
    #include <QLoggingCategory>
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <cstdio>
    #include "LoggingCategories.h"
    #include <QSqlQuery>
    
    QScopedPointer<QFile>   m_logFile;
    
    void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
    
    int main(int argc, char *argv[])
    {
    
        QApplication a(argc, argv);
        QString atrs = QString();
        MainWindow w;
        QObject::connect(&a, SIGNAL(aboutToQuit()),&w, SLOT(closing()));
    
        //qDebug()<<QSqlDatabase::drivers();
        for(int i=1; i< argc; i++)
        {
            atrs += argv[i];
            atrs += " ";
        }
    
        /// TODO: settings logs
        if(!QDir("logs").exists())
        {
           QDir().mkdir("logs");
        }
    
        m_logFile.reset(new QFile("logs/" +QDateTime::currentDateTime().toString("yyyy-MM-dd") + ".txt"));
        m_logFile.data()->open(QFile::Append | QFile::Text);
        qInstallMessageHandler(messageHandler);
    
        qInfo(logInfo()) << " ";
        qInfo(logInfo()) << "-------------------------------------------";
        qInfo(logInfo()) << "Start Program with args:" + atrs;
    
        /// TODO: settings DataBase
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setPort(3306);
        db.setUserName("*******");
        db.setPassword("********");
        db.setConnectOptions();
    
    
        if(db.open())
        {
            qInfo(logInfo()) << "Connect database";
        }
        else
        {
            qCritical(logCritical()) << "Error: can't open database";
        }
    
    
    
        w.show();
    
        return a.exec();
    }
    
    void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    {
    
        QTextStream out(m_logFile.data());
        out << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz ");
    
        switch (type)
        {
            case QtInfoMsg:     out << "INF "; break;
            case QtDebugMsg:    out << "DBG "; break;
            case QtWarningMsg:  out << "WRN "; break;
            case QtCriticalMsg: out << "CRT "; break;
            case QtFatalMsg:    out << "FTL "; break;
        }
    
        out << context.category << ": "
            << msg << endl;
        out.flush();
    }
    
    
    
    

  • Moderators

    @magalss I don't see Qt trying to load the MySQL plug-in - is this really the whole output?



  • @jsulm said in Qt Ubuntu QSqlDatabase: QMYSQL driver not loaded:

    @magalss I don't see Qt trying to load the MySQL plug-in - is this really the whole output?

    yeah,
    i set settings:
    alt text

    pro file:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2017-12-05T17:31:01
    #
    #-------------------------------------------------
    
    QT       += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = PaymentTerminal
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp \
        LoggingCategories.cpp
    
    HEADERS  += mainwindow.h \
        LoggingCategories.h
    
    FORMS    += mainwindow.ui
    
    


  • i found mysql information plugin

    Got keys from plugin meta data ("QSQLITE")
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/sqldrivers/libqsqlmysql.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/sqldrivers/libqsqlmysql.so, metadata=
    {
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
                "QMYSQL3",
                "QMYSQL"
            ]
        },
        "className": "QMYSQLDriverPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("QMYSQL3", "QMYSQL")
    QFactoryLoader::QFactoryLoader() looking at "/home/max/Qt/5.5/gcc/plugins/sqldrivers/libqsqlpsql.so"
    Found metadata in lib /home/max/Qt/5.5/gcc/plugins/sqldrivers/libqsqlpsql.so, metadata=
    {
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
                "QPSQL7",
                "QPSQL"
            ]
        },
        "className": "QPSQLDriverPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/max/ProjectTerminal/build-PaymentTerminal-Desktop-Debug/sqldrivers" ...
    
    


  • this create makefile solved problem

    /home/max/Qt/5.5/gcc/bin/qmake "LIBS+=-L/usr/lib/i386-linux-gnu -lmysqlclient_r" mysql.pro
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.