Integration MySQL and Qt5.7?



  • Hello everyone,
    I've been looking for a solution to get MySQL working with Qt 5.7 on a Ubuntu machine. The MySQL database is working properly, but I can't figure out how to make the drivers work for Qt. I have tried the SQL browser example code as a base to identify the problem. After trying to make connection to MySQL, the application output displays 'QSqlDatabase: QMYSQL driver not loaded' and 'QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7'. This got me confused at first as I thought they were there. After some googling for answer it seems the libmysqlclient_r.so.16 cannot be found. As it turns out I have .so.20 installed. The forums recommended on build them yourself. I don't quite understand how to qmake and make the appropriate files necessary to run the Mysql service. As so I have tried but have been unsuccessful so I come asking the forums for help. I'm not very experienced in Linux itself and a first time user of Qt.

    Any help would be greatly appreciated.
    Thanks in advance,
    Tom


  • Moderators

    @Tom_DE
    see this

    But make sure you link against the same Qt version and use the same compiler.
    Otherwise you will most probably experience random crashes (if the plugin even loads)



  • Thank you @raven-worx for the fast reply,
    I have followed the directions in the link provided before and from what understood from it, is that the $QTDIR/qtbase/src/plugins/sqldriver/mysql comes from the source code which you seperatly download?
    Perhaps I misunderstood this, but I haven't found the qtbase folder elsewhere.

    GCC Compiler version on my Ubuntu (which is 16.04) is 5.3.1, do you suggest downgrading it to the suggested version 4.8.1 for Ubuntu 14.04?
    The MySQL version my Ubuntu machine uses is as well a higher version: 5.7.12 should I downgrade it as well to the matching software version?

    Many thanks for your reply,
    Tom


  • Moderators

    @Tom_DE said:

    Thank you @raven-worx for the fast reply,
    I have followed the directions in the link provided before and from what understood from it, is that the $QTDIR/qtbase/src/plugins/sqldriver/mysql comes from the source code which you seperatly download?

    yes

    GCC Compiler version on my Ubuntu (which is 16.04) is 5.3.1, do you suggest downgrading it to the suggested version 4.8.1 for Ubuntu 14.04?

    yes, IIRC at least gcc's major version need to match to ensure binary compatibility.

    The MySQL version my Ubuntu machine uses is as well a higher version: 5.7.12 should I downgrade it as well to the matching software version?

    You can give it a try. You will encounter mysql related compiler/linker errors anyway if they are not compatible anymore.
    But i suggest you use the same version.



  • I've downgraded my GCC to 4.8.5 (i suspect it is close enough to the major version.
    I have not yet changed the MySQL version as it does not change the result of this problem.

    The source code I tried to qmake but it gives me an error : qmake: could not find a Qt installation of ''
    Is this because I have no qmake installation? Should I completly try to reinstall Qt for that?

    Kind thanks to you, @raven-worx for your help so far.


  • Moderators

    @Tom_DE said:

    The source code I tried to qmake but it gives me an error : qmake: could not find a Qt installation of ''
    Is this because I have no qmake installation? Should I completly try to reinstall Qt for that?

    to make sure call qmake with the absolute path



  • @raven-worx

    @raven-worx said:

    to make sure call qmake with the absolute path

    Could you elaborate on that? As in what the absolute is in : qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro ?


  • Moderators

    @Tom_DE

    /path/to/your/qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
    


  • Is the following command correct? (sorry for the lack of knowledge of Linux)

    delta@delta-engineering:~/Downloads/qt-everywhere-opensource-src-5.7.02/qtbase/src/plugins/sqldrivers$ /home/delta/Qt/5.7/gcc_64/bin/qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro

    If so this is the error it gives.
    Cannot find file: mysql.pro.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You have to go to the mysql plugin folder.


Log in to reply
 

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