Results 1 to 3 of 3

Thread: QMysql Driver not loaded

  1. #1
    Join Date
    Sep 2015
    Posts
    23
    Thanks
    1

    Default QMysql Driver not loaded

    When executing the following code I get an error that the Mysql driver is not loaded:

    Qt Code:
    1. db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("127.0.0.1");
    3. db.setDatabaseName("test");
    4. db.setUserName("test");
    5. db.setPassword("test");
    6.  
    7. if (!db.open()) {
    8. QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
    9. } else
    10. qDebug() << "OPEN";
    To copy to clipboard, switch view to plain text mode 

    and in my .pro file I added it with

    Qt Code:
    1. QT += core gui sql
    To copy to clipboard, switch view to plain text mode 


    I'm using Ubuntu 15.10 and I have installed
    libqt5sql5-mysql
    libqt4-sql-mysql

    and when locating them with I get
    Qt Code:
    1. locate libqsql
    2. /usr/lib/i386-linux-gnu/qt4/plugins/sqldrivers/libqsqlmysql.so
    3. /usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlite.so
    4. /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so
    To copy to clipboard, switch view to plain text mode 

    also when running the ldd command all dependencies can be found:
    Qt Code:
    1. ldd libqsqlite.so
    2. linux-vdso.so.1 => (0x00007fff631e6000)
    3. libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f831f6d3000)
    4. libQt5Sql.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5 (0x00007f831f691000)
    5. libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f831f1d4000)
    6. libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f831ee52000)
    7. libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f831ea88000)
    8. libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f831e869000)
    9. libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f831e665000)
    10. libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f831e44b000)
    11. libicui18n.so.55 => /usr/lib/x86_64-linux-gnu/libicui18n.so.55 (0x00007f831dfe7000)
    12. libicuuc.so.55 => /usr/lib/x86_64-linux-gnu/libicuuc.so.55 (0x00007f831dc53000)
    13. libpcre16.so.3 => /usr/lib/x86_64-linux-gnu/libpcre16.so.3 (0x00007f831d9f0000)
    14. libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f831d6e0000)
    15. librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f831d4d8000)
    16. libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f831d1d0000)
    17. libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f831cfb8000)
    18. /lib64/ld-linux-x86-64.so.2 (0x0000557933e71000)
    19. libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f831b501000)
    20. libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f831b293000)
    To copy to clipboard, switch view to plain text mode 

    Do I need to do something else?

  2. #2
    Join Date
    Aug 2008
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMysql Driver not loaded

    If you use QtCreator you need the mysql plugin. This is copied into the install directory
    .... /plugins/sqldrivers

    You need the following
    libqsqlite.so
    libqsqlmysql.so
    libqsqlpsql.so
    You can either create this with
    [CODE]
    cd $QTDIR/src/plugins/sqldrivers/mysql
    qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r" mysql.pro
    make
    [>CODE]
    or just use QtCreator and open the above project files, and compile, it could moan and display a error message as one cannot run a plugin directly.
    Now one just has to copy the created xx.so files into the plugin directory.

    On Ubuntu , you may need to install the development environment with
    Qt Code:
    1. sudo apt-get install libmysqlclient15-dev
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMysql Driver not loaded

    You seem to have three different Qt versions, 32 bit Qt4 and 64 bit Qt4 and Qt5. You need a consistent set of library of one "bitness". The Qt plugin for Mysql is already present for the basic 32bit Qt4 shown in the original post. These plugins are dependent on the Mysql runtime libraries (not part of Qt) that are likely not installed by default. You can check using ldd on the Mysql Qt plugin (not the Sqlite Qt plugin).

    If needed, use something like this to install the Mysql client library
    Qt Code:
    1. sudo apt-get install libmysqlclient15
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QMYSQL driver not loaded
    By shadowCODE in forum Installation and Deployment
    Replies: 3
    Last Post: 21st December 2014, 19:21
  2. QMYSQL driver not loaded
    By stef1570 in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2011, 05:59
  3. QMYSQL driver not loaded
    By robotics in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2011, 12:43
  4. QMYSQL driver not loaded
    By akhila in forum Newbie
    Replies: 1
    Last Post: 22nd February 2010, 18:24
  5. QMYSQL driver not loaded
    By sepehr in forum Qt Programming
    Replies: 12
    Last Post: 11th January 2009, 20:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.