Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. QSqlDatabase: QMYSQL driver not loaded / Build MySQL Plugin
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase: QMYSQL driver not loaded / Build MySQL Plugin

Scheduled Pinned Locked Moved Solved Installation and Deployment
qmysqlsqlmoduleubuntu 14.04linux mint
32 Posts 9 Posters 42.9k Views 4 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.
  • P Offline
    P Offline
    Peter Van Grieken
    wrote on last edited by
    #17

    Thanks!

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

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

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

      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
      • RalfSchaeferR Offline
        RalfSchaeferR Offline
        RalfSchaefer
        wrote on last edited by
        #19

        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/libqsqlmysql.so I got this:

        ldd /opt/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so 
               linux-vdso.so.1 (0x00007fffd7d83000)
               libmysqlclient.so.18 => /usr/lib64/libmysqlclient.so.18 (0x00007f9eb8607000)
                libz.so.1 => /lib64/libz.so.1 (0x00007f9eb83f0000)
                libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f9eb81b5000)
                libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f9eb7f9d000)
                libssl.so.1.0.0 => /lib64/libssl.so.1.0.0 (0x00007f9eb7d34000)
                libcrypto.so.1.0.0 => /lib64/libcrypto.so.1.0.0 (0x00007f9eb7941000)
                libQt5Sql.so.5 => /opt/Qt/5.5/gcc_64/lib/libQt5Sql.so.5 (0x00007f9eb7701000)
                libQt5Core.so.5 => /opt/Qt/5.5/gcc_64/lib/libQt5Core.so.5 (0x00007f9eb6fba000)
                libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9eb6d9d000)
                libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f9eb6a1b000)
                libm.so.6 => /lib64/libm.so.6 (0x00007f9eb6719000)
                libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9eb6502000)
                libc.so.6 => /lib64/libc.so.6 (0x00007f9eb615b000)
                libdl.so.2 => /lib64/libdl.so.2 (0x00007f9eb5f56000)
                libicui18n.so.54 => /opt/Qt/5.5/gcc_64/lib/libicui18n.so.54 (0x00007f9eb5ae8000)
                libicuuc.so.54 => /opt/Qt/5.5/gcc_64/lib/libicuuc.so.54 (0x00007f9eb5739000)
                libicudata.so.54 => /opt/Qt/5.5/gcc_64/lib/libicudata.so.54 (0x00007f9eb3d0f000)
                libgthread-2.0.so.0 => /usr/lib64/libgthread-2.0.so.0 (0x00007f9eb3b0d000)
                librt.so.1 => /lib64/librt.so.1 (0x00007f9eb3904000)
                libglib-2.0.so.0 => /usr/lib64/libglib-2.0.so.0 (0x00007f9eb35f5000)
                /lib64/ld-linux-x86-64.so.2 (0x000055fc1f3d8000)
                libpcre.so.1 => /usr/lib64/libpcre.so.1 (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;
            loader.setFileName("/opt/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so");
            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() << driverlist.at(i);
            }
        
            if (!db_opened)
            {
                    db = new QSqlDatabase();
                    qDebug() << "Step 1 - Database:    is valid=" << db->isValid();
                    db->addDatabase("QMYSQL3","cooptimedb");
                    qDebug() << "Step 2 - Database:    is valid=" << db->isValid();
        
                    db->setHostName("localhost");
                    db->setDatabaseName("cooptime");
                    db->setUserName("cooptime");
                    db->setPassword("...");
                    db->setPort(3306);
        
                    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"
        Databases: 
        "QSQLITE"
        "QMYSQL"
        "QMYSQL3"
        "QPSQL"
        "QPSQL7"
        Step 1 - Database:    is valid= false
        Step 2 - Database:    is valid= false
        Database
        ========
        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.

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

          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.

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

          RalfSchaeferR 1 Reply Last reply
          0
          • SGaistS SGaist

            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.

            RalfSchaeferR Offline
            RalfSchaeferR Offline
            RalfSchaefer
            wrote on last edited by
            #21

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

            1 Reply Last reply
            0
            • fikou1335F Offline
              fikou1335F Offline
              fikou1335
              wrote on last edited by fikou1335
              #22

              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

              libgcc_s.so.1 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 libgcc_s.so.1

              Can you help me please!

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

                Hi and welcome to devnet,

                Which architecture are on ?

                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
                • fikou1335F Offline
                  fikou1335F Offline
                  fikou1335
                  wrote on last edited by fikou1335
                  #24

                  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 libqsqlmysql.so 	linux-vdso.so.1 =>  (0x00007ffceb314000)
                  	libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (0x00007f7a884c6000)
                  	libQtSql.so.4 => /usr/local/Trolltech/Qt-4.8.6/lib/libQtSql.so.4 (0x00007f7a88285000)
                  	libQtCore.so.4 => /usr/local/Trolltech/Qt-4.8.6/lib/libQtCore.so.4 (0x00007f7a87d91000)
                  	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7a87a7f000)
                  	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7a87868000)
                  	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7a874a3000)
                  	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7a8728a000)
                  	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7a87086000)
                  	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7a86e68000)
                  	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7a86b62000)
                  	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7a8695a000)
                  	/lib64/ld-linux-x86-64.so.2 (0x00007f7a88c10000)
                  
                  

                  and this

                  Precision-M4600:/usr/lib/x86_64-linux-gnu$ ldd libmysqlclient.so.18
                  	linux-vdso.so.1 =>  (0x00007ffe50bc0000)
                  	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe8f4940000)
                  	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe8f473c000)
                  	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe8f451e000)
                  	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe8f4218000)
                  	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe8f3e53000)
                  	/lib64/ld-linux-x86-64.so.2 (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

                  Databases: QSQLITE QMYSQL3 QMYSQL

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

                  1 Reply Last reply
                  0
                  • fikou1335F Offline
                    fikou1335F Offline
                    fikou1335
                    wrote on last edited by
                    #25

                    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

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

                      What new library did you add ?

                      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
                      • fikou1335F Offline
                        fikou1335F Offline
                        fikou1335
                        wrote on last edited by
                        #27

                        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;
                            try
                            {
                                DB = QSqlDatabase::addDatabase( "QMYSQL");
                            }
                            catch(...)
                            {
                                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 (DB.open())
                            {
                                cout << "QMYSQL correctly connected "<< endl;
                            }
                            else
                            {
                                cout << "QMYSQL not connected "<< endl;
                            }
                        
                        
                            QApplication a(argc, argv);
                            QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
                            Dialog w;
                            w.show();
                        
                            return a.exec();
                        }
                        
                        

                        tell me if you got the same error.?

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

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

                          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
                          • fikou1335F Offline
                            fikou1335F Offline
                            fikou1335
                            wrote on last edited by
                            #29

                            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

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

                              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)

                              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
                              • H Offline
                                H Offline
                                Hervinsen
                                wrote on last edited by
                                #31

                                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 libqsqlmysql.so
                                  linux-vdso.so.1 => (0x00007ffcf0bf4000)
                                  libQt5Sql.so.5 => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007f28a7452000)
                                  libQt5Core.so.5 => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007f28a6d32000)
                                  libmysqlclient.so.20 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 (0x00007f28a66fa000)
                                  libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f28a6372000)
                                  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f28a5fa2000)
                                  libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f28a5d82000)
                                  libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f28a5a72000)
                                  libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f28a585a000)
                                  libicui18n.so.56 => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.56 (0x00007f28a53ba000)
                                  libicuuc.so.56 => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.56 (0x00007f28a5002000)
                                  libicudata.so.56 => /opt/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.56 (0x00007f28a361a000)
                                  libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f28a3412000)
                                  librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f28a320a000)
                                  libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f28a2fea000)
                                  libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f28a2de2000)
                                  libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f28a2aca000)
                                  /lib64/ld-linux-x86-64.so.2 (0x0000560448d0b000)
                                  libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f28a285a000)
                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  Amit Talbot
                                  wrote on last edited by
                                  #32

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

                                  brew install mysql-connector-c
                                  
                                  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