Qt5.8.0 mysql driver not found!



  • I have installed Qt5.8.0 on Ubuntu 16.04 and I wish to use mysql. mysql is installed in it default location (/usr/bin ) and runs fine from the command line.
    Running the Example program sqlbrowser, I find the error "Driver not loaded"
    This error is generated by the call: QSqlDatabase::addDatabase

    I have here (below) the simplest example of this difficulty. Here is the output from two calls:
    drivers = QSqlDatabase::drivers(); returns ("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7") which makes me think that QMYSQL means there is a connection to mysql.

    But, QSqlDatabase::addDatabase returns the driver not found error.

    I confirmed that after I installed sqlite, the addDatabase returns a good connection to sqlite.

    So, my question is what needs to be done to link Qt5.0 with it's libqsqlmysql.so library to my actual implementation of mysql?

    Below is a tiny bit of code and resulting output:
    /////////////////////// code
    #include <QCoreApplication>
    #include <QDebug>
    #include <QSqlDatabase>
    #include <QSqlError>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    qDebug() << "test mysql";
    QStringList drivers = QSqlDatabase::drivers();
    qDebug()<<"list drivers";
    qDebug()<<drivers;
    
    QString driverName = "QSQLITE";
    qDebug()<<"TRY -- addDatabase"<<driverName;
    QSqlError err;
    QSqlDatabase db = QSqlDatabase::addDatabase(driverName, "Browser0");
    err = db.lastError();
    qDebug()<<"lastError for"<<driverName<<"is"<<err;
    
    driverName = "QMYSQL";
    qDebug()<<" ";qDebug()<<"TRY -- addDatabase"<<driverName;
    db = QSqlDatabase::addDatabase(driverName, "Browser1");
    err = db.lastError();
    qDebug()<<"lastError for"<<driverName<<"is"<<err;
    
    return a.exec();
    

    }
    ////////////////////// Output
    test mysql
    list drivers
    ("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7")
    TRY -- addDatabase "QSQLITE"
    lastError for "QSQLITE" is QSqlError("", "", "")

    TRY -- addDatabase "QMYSQL"
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    lastError for "QMYSQL" is QSqlError("", "Driver not loaded", "Driver not loaded")


  • Lifetime Qt Champion

    Hi,

    Please run ldd libqsqlmysql.so to see against which version of MySQL it was built against. If different than yours then you'll have to re-build the plugin. Note that you do not have to re-build all of Qt, just the plugin.



  • Hi,
    Ldd reports the need for three libraries:
    ldd /home/val/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/libqsqlmysql.so

    libmysqlclient.so.18 => not found
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff7894e4000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff7892ca000)
    libssl.so.10 => not found
    libcrypto.so.10 => not found
    

    Hmmm. I struggled with this problem two years ago and here it is again. Mr. Gaist has suggested I need to do is rebuild the plugin. I have spent several days trying to do this without success. (Trying to follow http://doc.qt.io/qt-5/sql-driver.html ) If there is any clear path showing how to get qt to link to mysql, I would so love to find and follow it.
    Val


  • Lifetime Qt Champion

    What is not working for you ?

    Because basically you have to:

    1. Download Qt's source (you can do that through the installer or the maintenance tool)
    2. Unpack it if you downloaded the tar file
    3. Install the dev packages for the missing libraries from your distribution
    4. Follow the documentation

    Don't forget to use the full path to your installed Qt qmake otherwise you are going to use your distribution's Qt which is not what you want in this case.


Log in to reply
 

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