Important: Please read the Qt Code of Conduct -

MySQL support for Qt 5.1.1

  • Hi.. I have installed Qt 5.1.1 using apt-get install.
    I wrote a sample Qt application to connect to MySQL database and went into series of trouble.
    Currently I am getting the following error when I run the program.

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QPSQL

    From the many of the sources which I searched, I am understanding that the driver need to be compiled again.
    I need an expert advice on this please. Is that the entire Qt needs to be re-compiled including MySQL support or is there a way just to make this driver alone.

    Please help me fix this issue and move forward.

    Thanks much in advance

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since you are using debian/ubuntu you might be just missing MySQL. Check that you have it installed before anything else

  • Qt Champions 2017

    Check whether your plugins directory has driver for MYSQL. I suspect this issue.

  • Apologies for a late response.
    Yes, I installed MySQL server.

    /opt/Qt5.1.1/5.1.1/gcc/plugins dir has sqldrivers among others in which I see listed.

  • Lifetime Qt Champion

    it installed in /opt ? Are you sure you used apt-get for Qt 5 ?

    Anyway, call ldd on your Qt's sql plugin to see if it can find your MySQL libraries

  • Apologies again. I had the basic setup helped by a friend of mine.
    Actually the .run file was downloaded from Qt site and installed it.
    sudo -s chmod u+x ./

    The ldd output is copied below.
    test@lite2:/opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers$ ldd => (0xb76f5000) => not found => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/ (0xb7688000) => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/ (0xb7204000) => /usr/lib/i386-linux-gnu/ (0xb711f000) => /lib/i386-linux-gnu/ (0xb6f75000) => /lib/i386-linux-gnu/ (0xb6f5a000) => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/ (0xb6d38000) => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/ (0xb6bbe000) => /lib/i386-linux-gnu/ (0xb6bb9000) => /usr/lib/i386-linux-gnu/ (0xb6bb6000) => /lib/i386-linux-gnu/ (0xb6bad000) => /lib/i386-linux-gnu/ (0xb6ab4000) => /lib/i386-linux-gnu/ (0xb6a87000) => /lib/i386-linux-gnu/ (0xb6a69000)
    /lib/ (0xb76f6000) => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/ (0xb5520000) => /lib/i386-linux-gnu/ (0xb54e4000) not found in the result.
    I installed mysqlclient using apt-get how ever the shared object it could not be located.

  • I have in /usr/lib/i386-linux-gnu folder.

  • Lifetime Qt Champion

    It means you have a newer version of the MySQL library installed on your system. The most straight forward method now is to get Qt's sources and rebuild the plugin (only the plugin) and you should be good to go

  • Thanks for the reply.. and sorry to respond late.
    Well.. we need the Mysql server running in a different machine and the Qt application is to be used in an embedded environment with low memory footprint.

    In this case what would be the best way I can pull values from the Mysql tables.

  • Lifetime Qt Champion

    I suppose the embedded device will connect to the server through internet ?

    If so, you should rather use a web service for your device to communicate with the database.

  • Ok.. I have created an application using Qt Quick and using qml files hoping to have a low memory utilization.
    I am looking around for help in Qt. What would you suggest how should I be implementing the webservice call in this context? Is that should be handled in the application or in the qml file?
    Any reference on this will be very helpful.


  • And also, part of learning Qt, I wanted to rebuild the mysql plugin as you have mentioned. However friend of mine had the .run file to install Qt in the system as I told before.
    sudo -s chmod u+x ./

    That does not have the source code within.

    Therefore I downloaded Qt 5.1.1 source code from the below link, the tgz file

    And tried to build the plugin using already installed qmake binary file as below.

    /home/test/Downloads/Qt/qt-everywhere-opensource-src-5.1.1/qtbase/src/plugins/sqldrivers/psql/ INCLUDEPATH+=/usr/lib/i386-linux-gnu LIBS+=-L/usr/lib/i386-linux-gnu\ -lmysqlclient_r -o Makefile ) && make -f Makefile

    But got the following error message.
    ../../../sql/drivers/psql/qsql_psql.cpp:59:22: fatal error: libpq-fe.h: No such file or directory
    compilation terminated.
    make[1]: *** [.obj/release-shared/qsql_psql.o] Error 1
    make[1]: Leaving directory `/home/test/Downloads/Qt/qt-everywhere-opensource-src-5.1.1/qtbase/src/plugins/sqldrivers/psql'
    make: *** [sub-psql-make_first] Error 2

    Could you please help me resolve this.
    Is there a problem if I use the qmake from my first installation or do I require to build qmake from the downloaded source code?


  • Lifetime Qt Champion

    You are not building the MySQL plugin but the PostgreSQL

    For the web service part have a look at "libQxt": they provide some nice classes to help implement that

    Edit: link corrected

  • Thank you very much Sam. I was able to build the plugin for mysql.
    And the link provided for web service seems disconnected. Could you please check this.


  • Lifetime Qt Champion

    You're welcome !

    I've corrected the link

  • I have the plugin built and copied it from
    to /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers
    Renamed the old to in the same folder.

    lddtree results of the one copied is below:
    lddtree => ./ (interpreter => none) => /usr/lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /opt/Qt5.1.1/5.1.1/gcc/lib/ => /opt/Qt5.1.1/5.1.1/gcc/lib/ => not found => not found => /usr/lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /lib/i386-linux-gnu/ => /usr/lib/i386-linux-gnu/ => /lib/i386-linux-gnu/

    Please note that and do not have any sym links found.

    I am still getting the error when running the pgm.
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QMYSQL QMYSQL3 QSQLITE QPSQL QPSQL7
    QSqlQuery::exec: database not open

    Please tell me where did I go wrong.


  • Forgot to mention that added the newly compiled into the project pro file
    LIBS +=
    And mentioned the path in the Makefile
    LIBS = $(SUBLIBS) -L/opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/

  • Lifetime Qt Champion

    if it can't find libicu it won't load the plugin. It should be somewhere in /opt/Qt5.1.1/5.1.1/

Log in to reply