Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5.8.0 mysql driver not found!

Qt5.8.0 mysql driver not found!

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    orcav
    wrote on 21 Nov 2016, 20:31 last edited by
    #1

    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")

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Nov 2016, 22:08 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • O Offline
        O Offline
        orcav
        wrote on 25 Nov 2016, 05:37 last edited by
        #3

        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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 25 Nov 2016, 07:55 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          1/4

          21 Nov 2016, 20:31

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved