Notorious QSqlDatabase: QMYSQL driver not loaded but available



  • On a Gentoo system, I get the notorious Qt mysql error:

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    false

    This has numerous posts on various forums, some of which are unresolved.

    Simple code to reproduce the error is given in e.g. http://adamcavendish.is-programmer.com/posts/40431.html

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("test");
    db.setUserName("test");
    db.setPassword("xxxxxxxxxx");
    bool ok = db.open();
    qDebug() << ok;
    db.close();
    
    MainWindow w;
    w.show();
    
    return a.exec&#40;&#41;;
    

    }
    @
    I have in my project .pro file:

    QT += sql

    There are no compiler errors. However, as the link http://adamcavendish.is-programmer.com/posts/40431.html suggests, my issue is of this type:

    Using ldd I see that:

    $ ldd libqsqlmysql.so
    ./libqsqlmysql.so: /usr/lib64/libmysqlclient_r.so.16: version `libmysqlclient_16' not found (required by ./libqsqlmysql.so)

    Simply giving it this file as a symlink to the newer version (18) doesn't work.

    So in other words I'm assuming I need to recompile this libqsqlmysql.so to use the newer version?

    How do I go about compiling the new version?

    According to qtcreator/5.4/Src/README it is stated that: "A typical `configure; make' build process is used."

    I do configure (in qtcreator/5.4/Src), everything seems fine.

    I do make, and I get:

    g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_BOOTSTRAPPED -DQT_LITE_UNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CODECS -DQT_NO_DATASTREAM -DQT_NO_LIBRARY -DQT_NO_QOBJECT -DQT_NO_SYSTEMLOCALE -DQT_NO_THREAD -DQT_NO_UNICODETABLES -DQT_NO_USING_NAMESPACE -DQT_NO_DEPRECATED -DQT_NO_TRANSLATION -DQT_QMAKE_LOCATION="/usr/bin/qmake" -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_NO_CAST_FROM_ASCII -DQT_NO_DEBUG -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4 -I. -o qlatincodec.o ../../corelib/codecs/qlatincodec.cpp
    ../../corelib/codecs/qlatincodec.cpp:35:19: fatal error: qlist.h: No such file or directory
    #include "qlist.h"

    I've tried the following versions:

    Qt Creator 3.1.2 (opensource) Based on Qt 5.3.1 (GCC 4.6.1, 64 bit)
    Qt Creator 3.3.1 (opensource) Based on Qt 5.4.1 (GCC 4.6.1, 64 bit)


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are going to long way. You can just build the plugin itself against your MySQL version 18 library. See "here":http://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-4-and-higher



  • [quote author="SGaist" date="1425248560"]Hi and welcome to devnet,

    You are going to long way. You can just build the plugin itself against your MySQL version 18 library. See "here":http://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-4-and-higher[/quote]

    Thanks for the advice.

    I've attempted this procedure now, and sadly it fails. I think I'm giving incorrect arguments to qmake.

    I'm trying:

    $ qmake "INCLUDEPATH+=/usr/lib64" "LIBS+=-L/usr/lib64 -lmysqlclient_r" mysql.pro make
    WARNING: /home/devel/programs/qtcreator/5.4/Src/qtbase/src/plugins/sqldrivers/qsqldriverbase.pri:4: Unable to find file for inclusion qt_plugin
    Project MESSAGE: Warning: unknown QT: core-private
    Project MESSAGE: Warning: unknown QT: sql-private
    Cannot find file: make.

    The directory /usr/lib64 contains libmysqlclient. I tried some other options for INCLUDEPATH, e.g. I tried passing the directory ~/qtcreator/5.4/gcc_64/include/QtSql but all of my attempts result in the same error.


  • Lifetime Qt Champion

    Which qmake are you using ? You system's qmake or the 5.4 qmake ?



  • [quote author="SGaist" date="1425255019"]Which qmake are you using ? You system's qmake or the 5.4 qmake ?[/quote]

    I used my system qmake.

    When I use the one found at qtcreator/5.4/Src/qtbase/bin/qmake I get:

    $ ~/programs/qtcreator/5.4/Src/qtbase/bin/qmake "INCLUDEPATH+=/usr/lib64" "LIBS+=-L/usr/lib64 -lmysqlclient_r" mysql.pro make
    Project ERROR: No module claims plugin type 'sqldrivers'


  • Lifetime Qt Champion

    In what folder are you calling that ?



  • [quote author="SGaist" date="1425328932"]In what folder are you calling that ?[/quote]

    In qtcreator/5.4/Src/qtbase/src/plugins/sqldrivers/mysql

    Full command with prompt:

    ~/programs/qtcreator/5.4/Src/qtbase/src/plugins/sqldrivers/mysql $ qmake "INCLUDEPATH+=/usr/lib64" "LIBS+=-L/usr/lib64 -lmysqlclient_r" mysql.pro make


  • Lifetime Qt Champion

    If I read your like correctly you are calling your system installed qmake, or did I miss something ?


Log in to reply
 

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