Important: Please read the Qt Code of Conduct -

[SOLVED] Problems with Database Drivers (Linux)

  • My configuration is:
    Qt Creator 3.2.0
    Based on Qt 5.3.1 (GCC 4.6.1, 64 bit)
    From revision bld8156742

    Running on Linux Mint 17 KDE 64 Bit

    I am having problems loading the database driver.

    I have reduced things to as simple as possible, so that the database is being declared locally, though I initially had the same problem when it was declared it as a property within a class.

    I am trying to use Maria DB from a server, though it fails at the point of trying to load the driver, before it even tries to make the connection (so actually the database could be mysql, MariaDB or something else).

    It works for:

    • QSQLITE (which I use in other projects).

    I find that it Fails in the same way for:

    • QMYSQL
    • QMYSQL3
    • QPSQL
    • QPSQL7

    The error message I get is:
    @QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7@

    The header files I am using are:
    @#include <QObject>
    #include <QSqlDatabase>
    #include <QSqlQuery>
    #include <QMessageBox>
    #include <QVariant>
    #include <QSqlError>
    #include <QSqlDriver>
    #include <QDebug>@

    I copied the code from the Documentation on the Website:
    @QSqlDatabase m_DB = QSqlDatabase::addDatabase("QMYSQL");
    qDebug() << "1.\t"<< m_DB.isValid();

    I also tried this:
    @QSqlDatabase m_DB;
    m_DB = QSqlDatabase::addDatabase("QMYSQL");
    qDebug() << "1.\t"<< m_DB.isValid();@

    The isValid() method is false for every attempt other than the QSQLITE.

    This is what I have in my profile for the project:
    @QT += core gui
    QT += sql
    QT += network
    QT += printsupport

    CONFIG += qt warn_on
    CONFIG += c++11@

    Am I missing something obvious, not including a header or something like that, help would be apprieciated.

  • Qt Champions 2017

    You are missing the libraries MYSQL on your box. Ensure that all the required libraries for MYSQL are in path. There are many posts like "here": They will surely solve your problem.

    Look at following youtube video as well.

  • I used this "link": to help me.

    On my system $QTDIR wasn't set to anything, so I worked out where it was by searching for the "" file.

    When I tried to run qmake, I needed to use the 5.3 version, rather than any others, so I searched and found that and used the full path to it.

    @$cd /home/mike/Qt/5.3/Src/qtbase/src/plugins/sqldrivers/mysql
    sudo make install@

    I was confused because I felt the error message was telling me to use a driver that it also suggested was installed on the computer, the actual problem was that it lacked a dependency.

    I tried hard to resolve the dependency and then tried to just rebuild the library and that worked.

    Thanks to Dheerendra for the help.

Log in to reply