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



  • 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 libqsqlite.so libqsqlmysql.so libqsqlpsql.so 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 ./qt-linux-opensource-5.1.1-x86-offline.run

    The ldd output is copied below.
    test@lite2:/opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers$ ldd libqsqlmysql.so
    linux-gate.so.1 => (0xb76f5000)
    libmysqlclient_r.so.16 => not found
    libQt5Sql.so.5 => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0xb7688000)
    libQt5Core.so.5 => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0xb7204000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb711f000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6f75000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb6f5a000)
    libicui18n.so.51 => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/libicui18n.so.51 (0xb6d38000)
    libicuuc.so.51 => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/libicuuc.so.51 (0xb6bbe000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb6bb9000)
    libgthread-2.0.so.0 => /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 (0xb6bb6000)
    librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb6bad000)
    libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0xb6ab4000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb6a87000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb6a69000)
    /lib/ld-linux.so.2 (0xb76f6000)
    libicudata.so.51 => /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers/./../../lib/libicudata.so.51 (0xb5520000)
    libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb54e4000)

    libmysqlclient_r.so.16 not found in the result.
    I installed mysqlclient using apt-get how ever the shared object it could not be located.



  • I have libmysqlclient_r.so.18 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.

    Thanks.



  • 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 ./qt-linux-opensource-5.1.1-x86-offline.run

    That does not have the source code within.

    Therefore I downloaded Qt 5.1.1 source code from the below link, the tgz file
    http://mirrors.sohu.com/qt-all/official_releases/qt/5.1/5.1.1/single/

    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/psql.pro 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?

    Thanks


  • Lifetime Qt Champion

    You are not building the MySQL plugin but the PostgreSQL

    For the web service part have a look at "libQxt":http://libqxt.org/ 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.

    Thanks


  • Lifetime Qt Champion

    You're welcome !

    I've corrected the link



  • I have the plugin built and copied it from
    Qt/qt-everywhere-opensource-src-5.1.1/qtbase/plugins/sqldrivers
    to /opt/Qt5.1.1/5.1.1/gcc/plugins/sqldrivers
    Renamed the old libqsqlmysql.so to back_libqsqlmysql.so in the same folder.

    lddtree results of the one copied is below:
    lddtree libqsqlmysql.so
    libqsqlmysql.so => ./libqsqlmysql.so (interpreter => none)
    libmysqlclient.so.18 => /usr/lib/i386-linux-gnu/libmysqlclient.so.18
    libz.so.1 => /lib/i386-linux-gnu/libz.so.1
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2
    ld-linux.so.2 => /lib/i386-linux-gnu/ld-linux.so.2
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1
    libQt5Sql.so.5 => /opt/Qt5.1.1/5.1.1/gcc/lib/libQt5Sql.so.5
    libQt5Core.so.5 => /opt/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5
    libicui18n.so.51 => not found
    libicuuc.so.51 => not found
    libgthread-2.0.so.0 => /usr/lib/i386-linux-gnu/libgthread-2.0.so.0
    librt.so.1 => /lib/i386-linux-gnu/librt.so.1
    libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0
    libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6

    Please note that libicui18n.so.51 and libicuuc.so.51 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
    false
    QSqlQuery::exec: database not open

    Please tell me where did I go wrong.

    Thanks.



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


  • 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
 

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