Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to add QMySQL driver for Raspberry Pi?



  • Hi.
    I'm trying to install QMySQL driver on Raspberry Pi 3.
    I use cross-compile environment on Ubuntu 16.04 64bit.
    I can access remote MySQL database with Desktop kit option but can't with Raspberry pi kit.
    The error message are as follows:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE

    I found that I need to add MySQL driver for RPI or re-configure whole things with mysql options such as 'qt-sql-mysql' etc,.
    But I couldn't find a proper solution.

    I would appreciate if you give me any advice or tutorials.

    Thanks.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    No you don't have to recompile all of Qt. You can simply build the MySQL driver as long as you have the MySQL client libraries installed on your RPI3. You can then follow this guide.

    Hope it helps



  • @SGaist
    Hi.
    First, Thank you for your reply.

    I followed your link and read the post carefully.
    I tried to do that instruction(sub title is "How to Build the QMYSQL Plugin on Unix and OSX) line by line but
    there are somethings that I can't understand. Please refer to the image below (I commented my opinion).

    alt text


  • Lifetime Qt Champion

    Currently the image upload function is broken, can you use an image sharing site.

    See here on how to include the image in your post.



  • @SGaist

    I modified the image as your guide. Clicking the image will grow.

    Thank you.


  • Lifetime Qt Champion

    Seems like you didn't install the MySQL client libraries on your RPi3.

    If you can't find the mysql.pro file it's likely that you didn't download Qt's sources.



  • @SGaist

    I installed MySQL client libraried on my RPI3. libmysqlclient.so file could be found.
    And I didn't download Qt sources like you said.
    Because I thought that the MySQL driver for RPI would be made by cross-compilation.
    (MySQL driver for RPI is built on linux machine and is transferd into RPI.)
    Should I have both Qt source and MySQL client libraries in RPI3 and follow above instructions for building driver?


  • Lifetime Qt Champion

    My bad, I forgot you cross-compiled so you already should have the sources for that.

    If the MySQL dev package wasn't installed when cross-compiling Qt, then the driver won't be built. You can however follow the documentation by using the qmake from your cross-compiled Qt and the path to the sysroot where the libraries/headers can be found.



  • @SGaist

    I solved the problem. Thank you very much!!! :D


  • Lifetime Qt Champion

    You're welcome !

    What was the problem in the end ?



  • @SGaist

    I did 'qmake' that was created by cross-compilation as your guide.
    After that, compiled MySQL driver was copied into mounted RPI image.
    My mistake is that I understood instruction is need to be done on RPI.


  • Lifetime Qt Champion

    Cross-compilation is a tricky subject.

    Happy coding ! :)



  • @JamesDin

    Hi!

    So I followed the instructions here to cross-build a MySql driver. I have the same environment as you but I get this error:
    Project ERROR: Library 'mysql' is not defined.

    I am using Ubuntu Mate on my Raspberry Pi 3.

    mysql_config --include says -I/usr/include/mysql
    mysql_config --libs says -L/usr/lib/arm-linux-gnueabihf -lmysqlclient -lpthread -lz -lm -lrt -ldl

    So the line to compile I am using is:
    ${CROSS_BUILT_QMAKE}/./qmake "INCLUDEPATH+=${SYSROOT}/usr/include/mysql" "LIBS+=-L${SYSROOT}/usr/lib/arm-linux-gnueabihf -lmysqlclient_r" mysql.pro

    Any help would be appretiated.

    Thank you!



  • @SGaist
    Hello, I am new in Qt programming, I have the same situation as sir @andquesada . When i want to qmake the sql driver, the output is : Project ERROR: Library 'mysql' is not defined.

    Hope that you can help us. Thx


  • Lifetime Qt Champion

    Which version of Qt are you trying to build ?


Log in to reply