[SOLVED] QSqlDatabase: QMYSQL driver not loaded

  • I read a lot of forums but am still getting into trouble making this work. I'm working on Ubuntu 15.04.
    I used ldd on my libqsqlmysql.so, so it showed libmysqlclient_r.so.16 not found.
    I had libmysqlclient_r.so and libmysqlclient_r.so.18 in my library. I linked these both to my .16 file and tried running separately but it still did not run.
    Then i saw the method of building the QMYSQL plugin into my sqldrivers folder.
    So i did this:
    qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r" mysql.pro

    Ater this when i run make,
    it gives me the following error:
    g++ -c -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -I/usr/include/mysql -O2 -fvisibility=hidden -fvisibility-inlines-hidden -std=c++0x -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /usr/include/mysql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.4.1 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.4.1/QtCore -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.4.1 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.4.1/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.moc -I../../../../mkspecs/linux-g++-64 -o .obj/main.o main.cpp
    In file included from main.cpp:67:0:
    main.moc:12:2: error: #error "This file was generated using the moc from 4.8.6. It"
    #error "This file was generated using the moc from 4.8.6. It"
    main.moc:13:2: error: #error "cannot be used with the include files from this version of Qt."
    #error "cannot be used with the include files from this version of Qt."
    main.moc:14:2: error: #error "(The moc has changed too much.)"
    #error "(The moc has changed too much.)"
    main.moc:46:7: error: ‘QMetaObjectExtraData’ does not name a type
    const QMetaObjectExtraData QMYSQLDriverPlugin::staticMetaObjectExtraData = {
    main.moc:52:41: error: ‘staticMetaObjectExtraData’ was not declared in this scope
    qt_meta_data_QMYSQLDriverPlugin, &staticMetaObjectExtraData }
    main.moc: In member function ‘virtual const QMetaObject* QMYSQLDriverPlugin::metaObject() const’:
    main.moc:61:71: error: conditional expression between distinct pointer types ‘QDynamicMetaObjectData*’ and ‘const QMetaObject*’ lacks a cast
    return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
    main.moc:62:1: warning: control reaches end of non-void function [-Wreturn-type]
    Makefile:393: recipe for target '.obj/main.o' failed
    make: *** [.obj/main.o] Error 1

    This is my program:
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    bool ok = db.open();
    qDebug() << ok;

    I don't know what to do any further. Please Help.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    It seems you are trying to build a moc file that was generated when using Qt 4.8.6. Remove any moc file from your sources and restart the build.

  • Worked Perfectly. Thanks a lot Sir.

  • Lifetime Qt Champion

    You're welcome !

    Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

    Also, consider up-voting the answer(s) that helped you, it will allow other members to find them more easily.

Log in to reply

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