Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QSqlDatabase: QMYSQL driver not loaded
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QSqlDatabase: QMYSQL driver not loaded

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Antweb
    wrote on last edited by Antweb
    #1

    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");
    db.setHostName("localhost");
    db.setDatabaseName("student_info");
    db.setUserName("root");
    db.setPassword("terron@2003");
    bool ok = db.open();
    qDebug() << ok;
    db.close();

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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Antweb
        wrote on last edited by
        #3

        Worked Perfectly. Thanks a lot Sir.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved