Important: Please read the Qt Code of Conduct -

[solved] Driver not loaded QMYSQL

  • Hi all,

    I'm getting crazy with QMYSQL :(. I want to connet to a mysql server through this code (for testing the connection only). Qt version is 5.2.1, while OS is Ubuntu 13.10.

    #include <QCoreApplication>

    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlError>

    #include <QDebug>

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);
    qDebug() << "Started";
    qDebug() << "library path " << a.libraryPaths();

    QSqlDatabase db;
    qDebug() << db.drivers();
    qDebug() << "available = " << db.isDriverAvailable("QMYSQL");
    qDebug() << "db error=" &lt;&lt; db.lastError().databaseText();
    qDebug() &lt;&lt; "driver error=" &lt;&lt; db.lastError().driverText();
    bool done =;
    qDebug() << "done=" &lt;&lt; done;
    if (! done)
        qDebug() &lt;&lt; "Failed to open database";
        qDebug() << " - db error=" &lt;&lt; db.lastError().databaseText();
        qDebug() &lt;&lt; " - driver error=" &lt;&lt; db.lastError().driverText();
    qDebug() &lt;&lt; "Terminating";
    return a.exec&#40;&#41;;


    I get the following output:

    library path ("/home/fabio/Qt/5.2.1/gcc/plugins", "/home/fabio/Tests/Qt/build-TestDatabase-Desktop_Qt_5_2_1_GCC_32bit-Debug")
    available = true
    db error= "Driver not loaded"
    driver error= "Driver not loaded"
    done= false
    Failed to open database

    • db error= "Driver not loaded"
    • driver error= "Driver not loaded"

    As you can see, driver is not loaded, even if all libs are at the correct places and dependencies are satisfied.

    This is the past of the plugin dependencies
    fabio@ubuntu:~$ ldd /home/fabio/Qt/5.2.1/gcc/plugins/sqldrivers/ => (0xb77de000) => /usr/lib/i386-linux-gnu/ (0xb7492000) => /home/fabio/Qt/5.2.1/gcc/lib/ (0xb7453000) => /home/fabio/Qt/5.2.1/gcc/lib/ (0xb6f89000) => /usr/lib/i386-linux-gnu/ (0xb6ea0000) => /lib/i386-linux-gnu/ (0xb6cec000) => /lib/i386-linux-gnu/ (0xb6cd2000) => /lib/i386-linux-gnu/ (0xb6ccd000) => /lib/i386-linux-gnu/ (0xb6cb1000) => /lib/i386-linux-gnu/ (0xb6c6e000) => /lib/i386-linux-gnu/ (0xb6c51000) => /home/fabio/Qt/5.2.1/gcc/lib/ (0xb6a2f000) => /home/fabio/Qt/5.2.1/gcc/lib/ (0xb68b6000) => /usr/lib/i386-linux-gnu/ (0xb68b2000) => /lib/i386-linux-gnu/ (0xb68a9000) => /lib/i386-linux-gnu/ (0xb67a5000)
    /lib/ (0xb77df000) => /home/fabio/Qt/5.2.1/gcc/lib/ (0xb525c000) => /lib/i386-linux-gnu/ (0xb521a000)

    and, in the turn, the pasting of libmysqlclient which the plugin depends on:

    fabio@ubuntu:~$ ldd /usr/lib/i386-linux-gnu/ => (0xb773a000) => /lib/i386-linux-gnu/ (0xb73e6000) => /lib/i386-linux-gnu/ (0xb73e1000) => /lib/i386-linux-gnu/ (0xb73c5000) => /lib/i386-linux-gnu/ (0xb7382000) => /lib/i386-linux-gnu/ (0xb7365000) => /lib/i386-linux-gnu/ (0xb71b1000)
    /lib/ (0xb773b000)

    To be more precise, I have built the plugin directly from source code (5.2.1) and the database mentioned in the code really exists on

    I also tried with QMYSQL3 (same result).

    I really don't know what else to check.
    Please help me

    Thanks in advance

  • Solved,

    addDatabase is a static function and then correct way to create an instance of database is the following:

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");

    Sorry for the wasted time.


Log in to reply