Setting up the Qt Mysql driver with Lampp in Ubuntu

  • I'm trying to set up the Mysql driver for qt5 (5.6, specifically) in my Xubuntu computer. As the Mysql installation is Lampp based, the standard configuration script doesn't work to set it up. So I've tried configuring it Myself, this way:

    cd /opt/Qt5.6.3/5.6.3/Src/qtbase/src/plugins/sqldrivers/mysql
    sudo /opt/Qt5.6.3/5.6.3/Src/qtbase/bin/qmake "INCLUDEPATH+=/opt/lampp/lib" "LIBS+=-L/opt/lampp/lib -lmysqlclient_r"

    Still, I get this error:

    Project ERROR: No module claims plugin type 'sqldrivers'

    Any idea of what am I doing wrong? Thanks in advanced.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you build your own version of Qt inside the Src folder ?

  • Hello @SGaist

    One of my teammates prepared a Virtual Machine with Xubuntu and the Qt download. About building it, I'm not sure, if I do qmake version I get:

    qmake -version
    QMake version 2.01a
    Using Qt version 4.8.7 in /usr/lib/x86_64-linux-gnu

    So Xubuntu has the 4.8.7 version installed, but as I am going to develop for 5.6, I have it installed and Qt creator pointed to that folder. Is there anything I'm missing?

  • Lifetime Qt Champion

    Always use the full path to the qmake executable of the Qt version your want to use.

    There's no need to build the whole of Qt juste to build one of the plugin. The documentation of the SQL module provides the information about how to build specific DB plugins.

    You should also do out of source builds, it's never a good idea to build stuff as root.

  • Ok, then I should always use the full path and don't use sudo, I understand:

    /opt/Qt5.6.3/5.6.3/Src/qtbase/bin/qmake -version
    QMake version 3.0
    Using Qt version 5.6.3 in /usr/local/Qt-5.6.3/lib

    Then, based in the documentation, I'm going to try to build the plugin using the Makefile. I do:

    cd /opt/Qt5.6.3/5.6.3/Src/qtbase/src/plugins/sqldrivers
    /opt/Qt5.6.3/5.6.3/Src/qtbase/bin/qmake --MYSQL_PREFIX=/opt/lampp/lib Makefile

    And I get:

    Unknown option --MYSQL_PREFIX=/opt/lampp/lib
    Usage: /opt/Qt5.6.3/5.6.3/Src/qtbase/bin/qmake [mode] [options] [files]


    I'm now trying to follow the steps in docs for 5.6, which are slightly different. I try:

    cd /opt/Qt5.6.3/5.6.3/Src/qtbase/src/plugins/sqldrivers/mysql
    sudo /opt/Qt5.6.3/5.6.3/Src/qtbase/bin/qmake "INCLUDEPATH+=/opt/lampp/include" "LIBS+=-L/opt/lampp/lib -libmysqlclient_r" 

    And I get:

    Project ERROR: No module claims plugin type 'sqldrivers'

  • This steps seemed to properly configure the mysql driver. The way to check it is with this command:

    sudo /opt/Qt5.6.3/5.6.3/Src/configure -opensource -confirm-license -qt-sql-mysql -no-xcb -v

    And the output for the plugin list should be qt for the mysql driver. Then, I still couldn't connect from my Qt program. There were some missing libraries, which I detected using these commands:

    cd /opt/Qt5.6.3/gcc_64/plugins/sqldrivers

    Qt was looking for these libraries in the standard Unix path instead of the Lampp lib directory. So in the end I copied the missing libraries in the standard Unix path and got the connections working.

  • Lifetime Qt Champion

    You should set the LD_LIBRARY_PATH environment variable rather than modifying your system like that.

  • Lifetime Qt Champion

    @Aritz said in Setting up the Qt Mysql driver with Lampp in Ubuntu:

    sudo /opt/Qt5.6.3/5.6.3/Src/configure -opensource -confirm-license -qt-sql-mysql -no-xcb -v

    Why sudo?

Log in to reply