Nominate our 2022 Qt Champions!

QSqlDatabase: QMYSQL driver not loaded / Build MySQL Plugin

  • Hi,
    I'm experiencing the same problem that happens to anybody that is not expert too much expert in QT setup and wants to use QMYSQL plugin.

    There are a lot of topics on the forum but a 100% step-by-step guide is not found (and many things are changed during the time). Lots of people are asking help after trying to fix the problem by their self so they don't have a 100% clean / stock base. Instead I would like to receive assistance starting from a clean installation of the OS and QT.

    How to (step-by-step guide):

    • Clean Ubuntu 14.04 installation / Linux Mind 17 32bit
      if you are using 64bit, x86_64-linux-gnu would be the correct path for most things, instead of i386-linux-gnu as you are going to read in this thread

    • Installed QT in the user Home from
      Useful for unexperienced future readers:
      chmod u+x

    • During the installation select all "Source Components". This will download and install the sources useful to build plugins

    • Install a compiler
      sudo apt-get install g++
      sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev

    • Write you project and you will face problems with:
      db = QSqlDatabase::addDatabase("QMYSQL");

    • When you try to build your project you have this problem
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

    • Understand the problem running the commands:
      cd /home/[yourUsername]/Qt/[QtVersion]/gcc/plugins/sqldrivers

    • Read this line of the output: => not found

    • Install these packages
      sudo apt-get install libssl-dev
      sudo apt-get install libmysqlclient-dev

    • Now you should build the MYSQL plugin, according to documentation:
      cd /home/[yourUsername]/Qt/[QtVersion]/Src/qtbase/src/plugins/sqldrivers/mysql
      Then use the qmake provided in your Qt5.5 installation
      But it gives this error:
      /usr/bin/ld: cannot find -lmysqlclient_r

    • Make some symbolic links to make it working (please check mysql version, it could not be 18.1.0 in the future).
      sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/
      sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/
      sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/

    • Run again:
      It seems that the plugin have been built correctly. Last output is:
      mv -f ../../../../plugins/sqldrivers/
      and finally run:
      make install

    • Test your application.

  • Other resources (not required)
    The old
    And install with sudo dpkg -i [packageName].deb

    I also tried to copy renaming to
    sudo cp /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/
    But this method is not working, in fact ldd command says:
    /usr/lib/i386-linux-gnu/ version libmysqlclient_16 not found (required by Qt/5.5/gcc/plugins/sqldrivers/
    It seems it can understand it is not a true "version 16".

  • Lifetime Qt Champion


    It's more than just a number in your file name.

    Just rebuild the plugin using your currently installed MySQL library, it will be faster than trying to install version 16.

  • This post is deleted!

  • @SGaist updated the first post with the progress made with plugin build.

  • Lifetime Qt Champion

    You need to install the sources using the maintenance tool and call qmake from your Qt 5.5

  • @SGaist
    Thank for the tip about qmake.
    I have found and used the qmake from my Qt5.5 installation in /home/[myUsername]/Qt/5.5/gcc/bin/qmake
    Then I managed to run make too, so I think I successfully built the plugin.

    I have updated the first post, so other people can read it and follow step-by-step instruction. I'm not an expert of linux, so I you have some suggestion / improvements let me know and I'll edit the first post.

  • Lifetime Qt Champion

    You are doing something nasty: don't do the links to libmysqlclient_r yourself. You are missing the MySQL dev package. Install it and you're good to go.

  • Thank you, i manage to build the driver on one of my develop machines. However when i am doing the same on my other Linux machine it doesnt list it as an avaible driver even?
    [Qt run]
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC

    ~/Qt5.5.0/5.5/gcc_64/plugins/sqldrivers$ ls -l
    -rwxr-xr-x 1 user user 73368 okt 9 06:48
    » shows its been newly built

    ldd => /usr/lib/x86_64-linux-gnu/ (0x00007f6565b28000)
    » It have found the link

    » It seems like Qt dosnt know about it afterall.
    usualy qt's output list the driver atleast but doesnt show it as loaded untill its compiled.

    Edit: I tried load it during runtime
    QPluginLoader loader;
    » And it shows me this error: "The file '/home/' is not a valid Qt plugin.
    So something when wrong during building.

    » This error was kinda fun, there was a manually added path variable in qtcreator->Tools->Options->Build & Run->[Tab]Qt Versons. Where the Auto-detected where right and the Manual was pointing at an old qt4 version.
    After deleting that and rebuild the driver it worked..

  • Hi ,
    i am facing a different kind of issue. after doing ldd to inside sqldrivers folder am unable to see => not found this particular statement.
    Please help and reply ASAP.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Then, what do you see ?

  • @SGaist After doing ldd got this

    ldd => (0x00007ffd58adb000) => /usr/lib/ (0x00007f8a75afe000) => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f8a758bf000) => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f8a75236000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a74f32000) => /lib/x86_64-linux-gnu/ (0x00007f8a74b6d000) => /lib/x86_64-linux-gnu/ (0x00007f8a7490e000) => /lib/x86_64-linux-gnu/ (0x00007f8a74533000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a74268000) => /lib/x86_64-linux-gnu/ (0x00007f8a74064000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a73e1e000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a73bcd000) => /lib/x86_64-linux-gnu/ (0x00007f8a739af000) => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f8a73596000) => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f8a73210000) => /lib/x86_64-linux-gnu/ (0x00007f8a7300c000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a72e0a000) => /lib/x86_64-linux-gnu/ (0x00007f8a72c02000) => /lib/x86_64-linux-gnu/ (0x00007f8a728fa000) => /lib/x86_64-linux-gnu/ (0x00007f8a725f4000) => /lib/x86_64-linux-gnu/ (0x00007f8a723de000)
    /lib64/ (0x00007f8a75f42000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a721af000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a71fa4000) => /lib/x86_64-linux-gnu/ (0x00007f8a71da0000) => /lib/x86_64-linux-gnu/ (0x00007f8a71b85000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a71976000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a7175b000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a7151d000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a7125f000) => /lib/x86_64-linux-gnu/ (0x00007f8a70fdf000) => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f8a6f896000) => /lib/x86_64-linux-gnu/ (0x00007f8a6f658000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6f44f000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6f1c7000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6ef26000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6ecf3000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6eade000) => /lib/x86_64-linux-gnu/ (0x00007f8a6e8c5000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6e6b1000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6e46f000) => /lib/x86_64-linux-gnu/ (0x00007f8a6e26a000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6e041000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6de33000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6dbea000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6d931000) => /lib/x86_64-linux-gnu/ (0x00007f8a6d6f8000) => /usr/lib/x86_64-linux-gnu/ (0x00007f8a6d4f0000)

  • @SGaist sorry man that was my mistake i did ldd to a different .so file.


  • @mattewre: really good post! Tnx!
    @SGaist: I've been reading the forums and noticed you've been answering a lot of question asked by beginners like me. Thank you for the support!!

    This post really helped to understand this issue, but I've been trying to tackle the same problem for a few days now but for some reason I don't seem to be able to recompile the library "".

    1. What I can see
    • Compiling an application that uses mysql produces this output:

    loaded library "/home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/"
    QLibraryPrivate::loadPlugin failed on "/home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/" : "Cannot load library /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/ ( cannot open shared object file: No such file or directory)"
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

    • library:

    I do have the file located in /usr/lib/
    (note: I also have located in /usr/lib/ so during my frantic search for a solution I may have updated mysql again :-) ). I guess recompiling will link to the correct one?

    • doublechecking library dependency

    petervg@ubuntu:~/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers$ ldd => (0x00007ffc493bf000) => not found => /lib/x86_64-linux-gnu/ (0x00007f5ffbe74000) => /lib/x86_64-linux-gnu/ (0x00007f5ffbc3b000) => /lib/x86_64-linux-gnu/ (0x00007f5ffba21000) => not found => not found => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f5ffb7e0000) => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f5ffb09a000) => /lib/x86_64-linux-gnu/ (0x00007f5ffae7b000) => /usr/lib/x86_64-linux-gnu/ (0x00007f5ffaaf9000) => /lib/x86_64-linux-gnu/ (0x00007f5ffa7f1000) => /lib/x86_64-linux-gnu/ (0x00007f5ffa5d9000) => /lib/x86_64-linux-gnu/ (0x00007f5ffa20f000) => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f5ff9da0000) => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f5ff99f2000) => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f5ff7fc8000) => /lib/x86_64-linux-gnu/ (0x00007f5ff7dc4000) => /usr/lib/x86_64-linux-gnu/ (0x00007f5ff7bc1000) => /lib/x86_64-linux-gnu/ (0x00007f5ff79b9000) => /lib/x86_64-linux-gnu/ (0x00007f5ff76aa000)
    /lib64/ (0x00005569bd500000) => /lib/x86_64-linux-gnu/ (0x00007f5ff743c000)

    1. try to recompile from the source included with the offline installer.

    petervg@ubuntu:~/Qt5.5.1/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$ qmake
    petervg@ubuntu:~/Qt5.5.1/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$ make
    rm -f
    g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-rpath,/home/petervg/Qt5.5.1/5.5/gcc_64 -Wl,-rpath,/home/petervg/Qt5.5.1/5.5/gcc_64 -Wl,-rpath,/home/petervg/Qt5.5.1/5.5/gcc_64/lib -shared -o .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o -rdynamic -L/usr/lib64/mysql -lz -lcrypt -lnsl -lm -lssl -lcrypto -L/home/petervg/Qt5.5.1/5.5/Src/qtbase/lib -lQt5Sql -L/usr/local/lib -lmysqlclient_r -lQt5Core -lpthread
    /usr/bin/ld: cannot find -lQt5Sql
    /usr/bin/ld: cannot find -lQt5Core

    collect2: error: ld returned 1 exit status
    Makefile:142: recipe for target '../../../../plugins/sqldrivers/' failed
    make: *** [../../../../plugins/sqldrivers/] Error 1

    -> I'm not sure if this is relevant, but I can see the library Qt5Sql cannot be found even though in (1) i can see the library is found in /home/petervg/Qt5.5.1/5.5/gcc_64/lib.

    1. try to recompile from the source I downloaded (qt-everywhere-opensource-src-5.5.1).

    petervg@ubuntu:~/Downloads/qt-everywhere-opensource-src-5.5.1/qtbase/src/plugins/sqldrivers/mysql$ qmake
    petervg@ubuntu:~/Downloads/qt-everywhere-opensource-src-5.5.1/qtbase/src/plugins/sqldrivers/mysql$ make
    rm -f
    g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-rpath,/home/petervg/Qt5.5.1/5.5/gcc_64 -Wl,-rpath,/home/petervg/Qt5.5.1/5.5/gcc_64 -Wl,-rpath,/home/petervg/Qt5.5.1/5.5/gcc_64/lib -shared -o .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -lz -lcrypt -lnsl -lm -lssl -lcrypto -L/home/petervg/Downloads/qt-everywhere-opensource-src-5.5.1/qtbase/lib -lQt5Sql -lQt5Core -lpthread
    /usr/bin/ld: cannot find -lQt5Sql
    /usr/bin/ld: cannot find -lQt5Core

    collect2: error: ld returned 1 exit status
    Makefile:142: recipe for target '../../../../plugins/sqldrivers/' failed
    make: *** [../../../../plugins/sqldrivers/] Error 1

    -> identical results...

    1. Conclusion

    I've learned it's best to first make sure you have the latest mysql files installed before installing QT, so i guess I could completely reinstall Qt now, but I'ld like to learn what I have been doing wrong....

    Any tips where I should look further?

    With kind regards

  • (answering myself :-) )

    i open the in qtcreator (Coming from windows... I like an ide a lot more than the command line... sorry :-) ) and I added folowing line to this file:

    LIBS += -L/home/petervg/Qt5.5.1/5.5/gcc_64/lib

    I did this because I knew was located in /home/petervg/Qt5.5.1/5.5/gcc_64/lib.

    What I do need to look into, is WHY this works? In /etc/environment I added:

    • "PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/petervg/Qt5.5.1/Tools/QtCreator/bin/:/home/petervg/Qt5.5.1/5.5/gcc_64/lib:/home/petervg/Qt5.5.1/Tools/QtCreator/lib/qtcreator:/usr/lib"/x86_64-linux-gnu"

    and in /home/petervg/.profile I added:

    • LIBRARY_PATH="/home/petervg/Qt5.5.1/5.5/gcc_64/lib:/home/petervg/Qt5.5.1/5.5/gcc_64/plugins:/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH"
      export LIBRARY_PATH
      export LD_LIBRARY_PATH

    Neither of these solutions worked.

    But my problem us finally solved, so up to the next one... If anybody could shed some light as to why adding the line in the .PRO file worked, but not when adding the path to the environment variables... I'll be glad to know...


  • Lifetime Qt Champion


    The most simple way to ensure you're using the right qmake is to call it with the full path to the executable. One other problem comes from the fact that you also have Qt Creator's stuff in your PATH. Don't do it, Qt Creator comes with it's own build of Qt so that it's a complete autonomous application.

    The LIBS += -L/path/ tells the linker where to look for libraries.

  • Thanks!

    I'll take a good look at the PATH variable.

  • Lifetime Qt Champion

    Leave it clean, that way you ensure that you're not mixing things on your system while building the driver.

  • Hi,

    i'm facing a similiar sort of problem, not completely solvable by the steps above.
    I recompiled the QMYSQL-plugin and it's linked to the correct mysql-libraries.
    After doing ldd /opt/Qt/5.5/gcc_64/plugins/sqldrivers/ I got this:

    ldd /opt/Qt/5.5/gcc_64/plugins/sqldrivers/ 
  => /usr/lib64/ (0x00007f9eb8607000)
   => /lib64/ (0x00007f9eb83f0000)
   => /lib64/ (0x00007f9eb81b5000)
   => /lib64/ (0x00007f9eb7f9d000)
   => /lib64/ (0x00007f9eb7d34000)
   => /lib64/ (0x00007f9eb7941000)
   => /opt/Qt/5.5/gcc_64/lib/ (0x00007f9eb7701000)
   => /opt/Qt/5.5/gcc_64/lib/ (0x00007f9eb6fba000)
   => /lib64/ (0x00007f9eb6d9d000)
   => /usr/lib64/ (0x00007f9eb6a1b000)
   => /lib64/ (0x00007f9eb6719000)
   => /lib64/ (0x00007f9eb6502000)
   => /lib64/ (0x00007f9eb615b000)
   => /lib64/ (0x00007f9eb5f56000)
   => /opt/Qt/5.5/gcc_64/lib/ (0x00007f9eb5ae8000)
   => /opt/Qt/5.5/gcc_64/lib/ (0x00007f9eb5739000)
   => /opt/Qt/5.5/gcc_64/lib/ (0x00007f9eb3d0f000)
   => /usr/lib64/ (0x00007f9eb3b0d000)
   => /lib64/ (0x00007f9eb3904000)
   => /usr/lib64/ (0x00007f9eb35f5000)
            /lib64/ (0x000055fc1f3d8000)
   => /usr/lib64/ (0x00007f9eb338e000)

    So, erverything looks fine here.

    When I try to connect to the database, it still doesn't work. It seems, QSqlDatabase loads the plugin without problems, setting dabase specific stuff fails.

    My code-snippet, containing additional debug-stuff:

        QPluginLoader loader;
        qDebug() << "PluginLoader worked =" << loader.load();
        qDebug() << "Plugin Loader error=" << loader.errorString();
        QStringList driverlist =QSqlDatabase::drivers();
        qDebug() << "Databases: ";
        for (int i = 0; i < driverlist.size(); ++i)
            qDebug() <<;
        if (!db_opened)
                db = new QSqlDatabase();
                qDebug() << "Step 1 - Database:    is valid=" << db->isValid();
                qDebug() << "Step 2 - Database:    is valid=" << db->isValid();
                qDebug() << "Database\n========\nHostname: " << db->hostName() << "\nDatabasename: " << db->databaseName() << "\nUsername: " << db->userName() << "\nPassword: " << db->password()  << "\nPort: " << db->port();
                if (! db->open())
                    qDebug() << "db errorcode=" <<  db->lastError().nativeErrorCode();
                    qDebug() << "db errormessage=" << db->lastError() .text();

    The output of the code above is:

    PluginLoader worked = true
    Plugin Loader error= "Unknown error"
    Step 1 - Database:    is valid= false
    Step 2 - Database:    is valid= false
    Hostname:  "" 
    Databasename:  "" 
    Username:  "" 
    Password:  "" 
    Port:  -1
    db errorcode= ""
    db errormessage= "Driver not loaded Driver not loaded"

    So it seems, the driver still doesn't load.

    Any help would be very appreciated. Thanks in advance.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Your code is wrong, you are creating an invalid QSqlDatabase object on the heap and then you call a static function on it.

    Please take a look at QSqlDatabase's detailed documentation. There's an example there on how to do the setup and connection.

  • @SGaist Thanks for your help!! That's it. Now all works fine for me!

  • Hi SGaist,

    I have a new problem with QMysql, everything worked fine since today, actually when I executede this line

        DB = QSqlDatabase::addDatabase( "QMYSQL");

    I have this error must be installed for pthread_cancel to work

    I don't know why,

    the plugin is correctly compiled without error, and using the ldd he found the

    Can you help me please!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Which architecture are on ?

  • Hi and thanks for your quick response

    I m working on Ubuntu 64bits
    i got this

    Precision-M4600:/usr/local/Trolltech/Qt-4.8.6/plugins/sqldrivers$ ldd =>  (0x00007ffceb314000) => /usr/lib/x86_64-linux-gnu/ (0x00007f7a884c6000) => /usr/local/Trolltech/Qt-4.8.6/lib/ (0x00007f7a88285000) => /usr/local/Trolltech/Qt-4.8.6/lib/ (0x00007f7a87d91000) => /usr/lib/x86_64-linux-gnu/ (0x00007f7a87a7f000) => /lib/x86_64-linux-gnu/ (0x00007f7a87868000) => /lib/x86_64-linux-gnu/ (0x00007f7a874a3000) => /lib/x86_64-linux-gnu/ (0x00007f7a8728a000) => /lib/x86_64-linux-gnu/ (0x00007f7a87086000) => /lib/x86_64-linux-gnu/ (0x00007f7a86e68000) => /lib/x86_64-linux-gnu/ (0x00007f7a86b62000) => /lib/x86_64-linux-gnu/ (0x00007f7a8695a000)
    	/lib64/ (0x00007f7a88c10000)

    and this

    Precision-M4600:/usr/lib/x86_64-linux-gnu$ ldd =>  (0x00007ffe50bc0000) => /lib/x86_64-linux-gnu/ (0x00007fe8f4940000) => /lib/x86_64-linux-gnu/ (0x00007fe8f473c000) => /lib/x86_64-linux-gnu/ (0x00007fe8f451e000) => /lib/x86_64-linux-gnu/ (0x00007fe8f4218000) => /lib/x86_64-linux-gnu/ (0x00007fe8f3e53000)
    	/lib64/ (0x00007fe8f5091000)

    If I comment the addBase line in my code everything works fine without connecting to the Database of course.
    when I try to list the drivers using

    QStringList driverlist =QSqlDatabase::drivers();

    I got this


    Everything works fine Monday, I checked the database, I could write on it fine,, but yesterday, it crash my application
    hope it can help!

  • I have just created a new app with the main function and it works and connect fine to my database.

    In my code I comment all the last code that I added this week and SURPRISE it works as well.
    the problem is probably due to a third library that i started to use this week. I ll check why it cause a crach to mysql o_O

  • Lifetime Qt Champion

    What new library did you add ?

  • This one Dahua SDK

    You can check by yourslef, they have a source example, PTZControl that works fine, but try to add

          DB = QSqlDatabase::addDatabase( "QMYSQL");   

    and you should get the same error.

    this sdk is used to control PTZ cams of Dahua brand.
    I changed my code by creating a new app to control cameras and get the informations of position from my big application.

    put this main instsead of it

    #include <QtGui/QApplication>
    #include "dialog.h"
    #include <QTextCodec>
    #include <QObject>
    #include <QtSql/QSqlDatabase>
    #include <QStringList>
    #include <QtSql/QSqlQuery>
    #include <QtSql/QSqlRecord>
    #include <QVariant>
    #include <iostream>
    int main(int argc, char *argv[])
        QSqlDatabase DB;
        cout <<endl<< "try connect MYSQL "<< endl;
            DB = QSqlDatabase::addDatabase( "QMYSQL");
            cout << "fatal error"<< endl;
        cout << "add database"<< endl;
        DB.setDatabaseName( "intrusiondetection" );
        DB.setUserName( "root" );
        DB.setPassword( "root" );
        cout << "1"<< endl;
        DB.setHostName( "" );
        cout << "try to connect"<< endl;
        if (
            cout << "QMYSQL correctly connected "<< endl;
            cout << "QMYSQL not connected "<< endl;
        QApplication a(argc, argv);
        Dialog w;;
        return a.exec();

    tell me if you got the same error.?

  • Lifetime Qt Champion

    One thing that you should first correct: move the database initialization code after the QApplication object creation.

  • i already tried every configuration but doesn't work! just a question by the way:
    Is the QDbus available on the Ubuntu system since they said it is Unix only library..? I try to communicate between PTZcontrol process and my application

  • Lifetime Qt Champion

    Ubuntu is a unix based OS since it's based on the Debian distribution. QDBus is available on Linux, OS X and Windows (the two later requires that you install dbus by hand)

  • Thanks to your guide, it is working on Kubuntu 16 with Qt 5.8
    here is my output :

    • /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ ldd => (0x00007ffcf0bf4000) => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f28a7452000) => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f28a6d32000) => /usr/lib/x86_64-linux-gnu/ (0x00007f28a66fa000) => /usr/lib/x86_64-linux-gnu/ (0x00007f28a6372000) => /lib/x86_64-linux-gnu/ (0x00007f28a5fa2000) => /lib/x86_64-linux-gnu/ (0x00007f28a5d82000) => /lib/x86_64-linux-gnu/ (0x00007f28a5a72000) => /lib/x86_64-linux-gnu/ (0x00007f28a585a000) => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f28a53ba000) => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f28a5002000) => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007f28a361a000) => /lib/x86_64-linux-gnu/ (0x00007f28a3412000) => /lib/x86_64-linux-gnu/ (0x00007f28a320a000) => /lib/x86_64-linux-gnu/ (0x00007f28a2fea000) => /usr/lib/x86_64-linux-gnu/ (0x00007f28a2de2000) => /lib/x86_64-linux-gnu/ (0x00007f28a2aca000)
      /lib64/ (0x0000560448d0b000) => /lib/x86_64-linux-gnu/ (0x00007f28a285a000)

  • im using qt 5.9 on mac this piece of code worked like charm for me

    brew install mysql-connector-c