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. Qt 5.1.0 and MySQL 5.5.32 "Driver not loaded"

Qt 5.1.0 and MySQL 5.5.32 "Driver not loaded"

Scheduled Pinned Locked Moved Installation and Deployment
22 Posts 7 Posters 29.0k Views
  • 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
    pgroen
    wrote on last edited by
    #1

    Hi All,

    It has been asked many times and I tried several answers, but still no luck. I did the following :

    1. Installed qt-linux-opensource-1.4.0-x86_64-online.run on Fedora 18
    2. Selected everything and installed it in /opt/Qt
    3. Tried compiling the following sources :

    @
    QSqlDatabase m_database = QSqlDatabase::addDatabase( "QMYSQL", "DefaultDb" );
    m_database.setDatabaseName( "face_scanner" );
    m_database.setUserName( "<username>" );
    m_database.setPassword( "<password>" );
    m_database.setHostName( "<DB_Server>" );

    if ( m_database.open() )
    {
        QString     sqlQuery;
        QSqlQuery   oQuery;
    
        // First we empty the entire table..
    
        qDebug() << "Deleting data from tbl_images";
        sqlQuery = "DELETE * FROM tbl_images";
        if( !oQuery.exec&#40; sqlQuery &#41; &#41;
        {
            qDebug() << oQuery.lastError().text();
        }
        else
        {
            qDebug() << "Data deleted succesfully";
        }
    

    @
    =============================
    4. At first the error states : QMYSQL driver not loaded
    5. Followed instructions to compile and install the sql_pugins. No errors and installed as expected.
    6. Tried to compile and run the code again...
    7. The following errormessage is displayed... "Driver not loaded"

    I'm stuck at the moment.. Anyone can help?

    Peter M. Groen
    Open Systems Development

    'Will Killing Time Affect The Future?'
    'I think It Will, In The End'

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

      Hi,

      Check that the loader can find the MySQL libraries. You can use ldd on the plugin to see if all linked libraries are found, if not update the LD_LIBRARY_PATH environment variable to also point where the MySQL libraries can be found.

      Before modifying your system, you can do it in the run panel of Qt Creator

      Hope it helps

      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
        ArcNexus
        wrote on last edited by
        #3

        have you copied generated libqsqlmysql.so into your qt5.1 5.1.0/gcc/plugins/sqldrivers/?

        But beware, in this directory exist a file called same, but it does not work fine, you need replace it with generated new .so file.

        good luck

        When we are one, we win

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pgroen
          wrote on last edited by
          #4

          ArcNexus : Yes I did. Unfortunately it didn't do any good...
          SGaist : According to ldd, there are no missing libraries. (Checked that earlier)
          What Run panel are you talking about? Looked in Options but couldn't find any.. (Qt Creator 2.8.0)

          As a last resort, I deleted the entire installation and downloaded the source. Configured it with :

          =====================
          @
          ./configure -debug -silent -prefix /opt/Qt -qt-sql-sqlite -qt-sql-sqlite2 -qt-sql-mysql -L/usr/lib64/mysql -I/usr/include/mysql -qt-sql-psql -I/usr/include/pgsql -L/usr/lib64/pgsql

          and started the configure. The Summary doesn't show any problems and compiling doesn't produce any errors. So far so good!

          =====================
          Configure summary

          Build type: linux-g++ (x86_64, CPU features: mmx sse sse2)
          Platform notes:

                  - Also available for Linux: linux-kcc linux-icc linux-cxx
          

          Build options:
          Configuration .......... accessibility accessibility-atspi-bridge alsa audio-backend avx avx2 c++11 clock-gettime clock-monotonic concurrent cups dbus debug egl evdev eventfd fontconfig full-config getaddrinfo getifaddrs glib gstreamer gtk2 gtkstyle iconv icu inotify ipv6ifname large-config largefile libudev linuxfb medium-config minimal-config mremap nis opengl openssl png precompile_header qpa qpa reduce_exports reduce_relocations rpath shared silent small-config sse2 sse3 sse4_1 sse4_2 ssse3 system-freetype system-jpeg system-png system-zlib v8 v8snapshot xcb xcb-glx xcb-render xcb-xlib xinput2 xlib xrender
          Build parts ............ libs tools examples
          Mode ................... debug
          Using C++11 ............ yes
          Using PCH .............. yes
          Target compiler supports:
          SSE2/SSE3/SSSE3 ...... yes/yes/yes
          SSE4.1/SSE4.2 ........ yes/yes
          AVX/AVX2 ............. yes/yes

          Qt modules and options:
          Qt D-Bus ............... yes (loading dbus-1 at runtime)
          Qt Concurrent .......... yes
          Qt GUI ................. yes
          Qt Widgets ............. yes
          JavaScriptCore JIT ..... yes (To be decided by JavaScriptCore)
          QML debugging .......... yes
          Use system proxies ..... no

          Support enabled for:
          Accessibility .......... yes
          ALSA ................... yes
          CUPS ................... yes
          FontConfig ............. yes
          Iconv .................. yes
          ICU .................... yes
          Image formats:
          GIF .................. yes (plugin, using system library)
          JPEG ................. yes (plugin, using system library)
          PNG .................. yes (in QtGui, using system library)
          Glib ................... yes
          GStreamer .............. yes
          GTK theme .............. yes
          Large File ............. yes
          libudev ................ yes
          Networking:
          getaddrinfo .......... yes
          getifaddrs ........... yes
          IPv6 ifname .......... yes
          OpenSSL .............. yes (loading libraries at run-time)
          NIS .................... yes
          OpenGL ................. desktop
          OpenVG ................. no
          PCRE ................... system
          pkg-config ............. yes
          PulseAudio ............. no
          QPA backends:
          DirectFB ............. no
          EGLFS ................ no
          KMS .................. no
          LinuxFB .............. yes
          XCB .................. yes (system library)
          MIT-SHM ............ yes
          Xcursor ............ yes (loaded at runtime)
          Xfixes ............. yes (loaded at runtime)
          Xi ................. no
          Xi2 ................ yes
          Xinerama ........... yes (loaded at runtime)
          Xrandr ............. yes (loaded at runtime)
          Xrender ............ yes
          XKB ................ yes
          XShape ............. yes
          XSync .............. yes
          XVideo ............. yes
          Session management ..... yes
          SQL drivers:
          DB2 .................. no
          InterBase ............ no
          MySQL ................ qt
          OCI .................. no
          ODBC ................. no
          PostgreSQL ........... qt
          SQLite 2 ............. qt
          SQLite ............... qt-qt
          TDS .................. no
          udev ................... yes
          xkbcommon .............. yes
          zlib ................... yes (system library)
          @

          Ran "su -c "gmake install" and added the $QTDIR/lib to the linker cache.
          Set QTDIR and path to .bashrc .

          Downloaded, compiled and installed Qt-Creator 2.8.0 and tried to build my project again... Nothing... Still the "driver not loaded" error appears.

          And now I'm out of options. If anyone has more suggestions, please let me know.

          Kind Regards,

          Peter

          Peter M. Groen
          Open Systems Development

          'Will Killing Time Affect The Future?'
          'I think It Will, In The End'

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ArcNexus
            wrote on last edited by
            #5

            Can you test what is the result of this?
            @
            qDebug() << "drivers: "<< QSqlDatabase::drivers();@

            When we are one, we win

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pgroen
              wrote on last edited by
              #6

              Yes. I can :)

              ( "QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7" )

              So.. All drivers present, known and ready. There is only no action.. :(

              Peter M. Groen
              Open Systems Development

              'Will Killing Time Affect The Future?'
              'I think It Will, In The End'

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ArcNexus
                wrote on last edited by
                #7

                When driver is in list and it not work fine, i then replace .so file with new compiled .so in qt5 plugins directory and it all times works fine.

                Check this from terminal:

                @sudo cp /home/youruser/yourbuilddirectory/qsqlmysql.so /yourqt5directory/gcc/plugins/sqldrivers/@

                Or do it manualy in nautilus with sudo privileges

                If compiled driver .so file is in this directory it works correctly all times.

                If you do it and it not work fine i think the problem is in your .so. In this case recompile it and check if are fine compiled and replace .so again.

                When we are one, we win

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sahumada
                  wrote on last edited by
                  #8

                  @PeterMGroen

                  you dont need to compile the plugin. it comes with the package you downloaded under ~/Qt/5.1.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so

                  that's why you see "QMYSQL" when you run QSqlDatabase::drivers();

                  do you have the mysql devel package installed ?

                  it works for me out of the box from Fedora 16 to Fedora 18.

                  Sergio Ahumada

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vallidor
                    wrote on last edited by
                    #9

                    I had the same issue with Qt 5.1.1.

                    The included libqsqlmysql.so driver appears to be linked against an incompatible libmysqlclient when using mariadb.

                    I haven't found a solution yet which doesn't involve rebuilding Qt from scratch.

                    (Rebuilding just the Sql module appears to link the mysql driver code into libQt5Sql.so which isn't what I want...)

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sahumada
                      wrote on last edited by
                      #10

                      mmm .. I am not sure if this is supposed to work with MariaDB out of the box ..

                      which MariaDB packages did you install ?

                      when you rebuilt Qt .. which configure option did you use ? did you use -plugin-sql-mysql ?

                      Sergio Ahumada

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kalempir
                        wrote on last edited by
                        #11

                        I have the same problem like PeterMGroen.
                        QT: online installation.
                        OS: ubuntu desktop 12.04
                        Mysql: 5.5

                        I made @ldd libqsqlmysql.so@ and saw that it cannot find one lib file. So I compiled new libqsqlmysql.so and place it sqldrivers folder of qt env.
                        also made copy of it to "application folder/sqldrivers" folder. Not success.

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          vtyulb
                          wrote on last edited by
                          #12

                          Hello everybody!

                          I had the same problem on Debian 7. Solve is - use QPluginLoader.

                          @QPluginLoader loader("path-to-your-driver/libqsqlmysql.so");
                          loader.load();
                          qDebug() << loader.errorString();@

                          So, it said to me that I had not one library. I installed it, and all works now!

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            kalempir
                            wrote on last edited by
                            #13

                            [quote author="vtyulb" date="1386142729"]Hello everybody!

                            I had the same problem on Debian 7. Solve is - use QPluginLoader.

                            @QPluginLoader loader("path-to-your-driver/libqsqlmysql.so");
                            loader.load();
                            qDebug() << loader.errorString();@

                            So, it said to me that I had not one library. I installed it, and all works now![/quote]

                            I tried, but got this message:
                            @"Unknown error"
                            drivers: ("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7")
                            "Driver not loaded Driver not loaded" @

                            My connection code is
                            @db = new QSqlDatabase();
                            db->addDatabase("QMYSQL", "DB");
                            db->setHostName("localhost");
                            db->setDatabaseName("myclinic");
                            db->setUserName("root");
                            db->setPassword(",trth12");

                            QPluginLoader loader("./sqldrivers/libqsqlmysql.so");
                            loader.load();
                            
                            qDebug() << loader.errorString();
                            
                            
                            qDebug() << "drivers: "<< QSqlDatabase::drivers();
                            
                            if (db->open())
                                qDebug() << "Success!";
                            else
                                qDebug() << db->lastError().text();
                            

                            @

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              vtyulb
                              wrote on last edited by
                              #14

                              I think it is a good idea to move sqldrivers to folder "plugins".
                              @vlad@vtyulb:~/server$ ls
                              config.ini plugins Server
                              vlad@vtyulb:~/server$ ls plugins/sqldrivers/
                              libqsqlmysql.so
                              @

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                kalempir
                                wrote on last edited by
                                #15

                                [quote author="vtyulb" date="1386169653"]I think it is a good idea to move sqldrivers to folder "plugins".
                                @vlad@vtyulb:~/server$ ls
                                config.ini plugins Server
                                vlad@vtyulb:~/server$ ls plugins/sqldrivers/
                                libqsqlmysql.so
                                @[/quote]

                                I don't understand what you mean.
                                For me it seems the problem is qt see mysql driver, but can not load. The error message as I show above is "Unknown error".

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  vtyulb
                                  wrote on last edited by
                                  #16

                                  As I know:
                                  Qt by default search plugins at directory "./plugins/"
                                  So, right tree:
                                  ./binary-file
                                  ./plugins/sqldrivers/libqsqlmysql.so

                                  I didn't work with QPluginLoader, but I think, that "Unknown error" means that everything OK. When I installed library, I got this message.

                                  So, I think it is a good idea to remove QPluginLoader from code, and
                                  improve filesystem tree.

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    kalempir
                                    wrote on last edited by
                                    #17

                                    ok, I tried your advice before, but I am going to try it again.

                                    1 Reply Last reply
                                    0
                                    • K Offline
                                      K Offline
                                      kalempir
                                      wrote on last edited by
                                      #18

                                      Any changes. I removed QPluginLoader object, but the error "Driver not loaded" remain.
                                      It makes me crazy, I am spending about 1 week to solve this issue, and not solved it yet.

                                      I saw suggestions for windows platforms to copy libmysql.dll in project root directory. What is the name of this file in linux?

                                      1 Reply Last reply
                                      0
                                      • V Offline
                                        V Offline
                                        vtyulb
                                        wrote on last edited by
                                        #19

                                        [quote author="kalempir" date="1386238296"]Any changes. I removed QPluginLoader object, but the error "Driver not loaded" remain.
                                        It makes me crazy, I am spending about 1 week to solve this issue, and not solved it yet.

                                        I saw suggestions for windows platforms to copy libmysql.dll in project root directory. What is the name of this file in linux?[/quote]

                                        I think libmysql.dll == libmysqlclient_r.so.
                                        But if QPluginLoader loads plugin without problems, it is very strange, that Qt can't load it.

                                        Here is my connection code:
                                        @QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                                        db.setHostName("localhost");
                                        db.setDatabaseName("safecloud");
                                        db.setUserName(mySqlLogin);
                                        db.setPassword(mySqlPassword);
                                        @

                                        I got another idea. If you compile program on one system and copy it to another, it can be a situation:
                                        On target system there is Qt of another version. It has plugins, but incompatible versions. When you start program, it searches for plugins. It finds plugins in Qt on target system, but if versions of Qt are different, it can't load it.

                                        So, if there is a Qt on target system, you can try to do command like this:

                                        @cp ./plugins/sqldrivers/libqsqlmsql.so /opt/Qt/5.1.1/gcc_64/plugins/sqldrivers/libqsqlmysql.so@

                                        Are you compile and run program on the same systems?

                                        1 Reply Last reply
                                        0
                                        • K Offline
                                          K Offline
                                          kalempir
                                          wrote on last edited by
                                          #20

                                          [quote author="vtyulb" date="1386242785"]

                                          I think libmysql.dll == libmysqlclient_r.so.

                                          But if QPluginLoader loads plugin without problems, it is very strange, that Qt can't load it.

                                          Here is my connection code:
                                          @QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                                          db.setHostName("localhost");
                                          db.setDatabaseName("safecloud");
                                          db.setUserName(mySqlLogin);
                                          db.setPassword(mySqlPassword);
                                          @

                                          I got another idea. If you compile program on one system and copy it to another, it can be a situation:
                                          On target system there is Qt of another version. It has plugins, but incompatible versions. When you start program, it searches for plugins. It finds plugins in Qt on target system, but if versions of Qt are different, it can't load it.

                                          So, if there is a Qt on target system, you can try to do command like this:

                                          @cp ./plugins/sqldrivers/libqsqlmsql.so /opt/Qt/5.1.1/gcc_64/plugins/sqldrivers/libqsqlmysql.so@

                                          Are you compile and run program on the same systems?[/quote]

                                          Yes, I compiled and run program in the same system.
                                          System is Ubuntu Desktop 12.04, 32 bit.
                                          When I try to compile mysql driver by QtCreator, I get error
                                          @mv -f libqsqlmysql.so /plugins/sqldrivers/
                                          mv: cannot move libqsqlmysql.so' to /plugins/sqldrivers/libqsqlmysql.so': Permission denied
                                          { test -z "/plugins/sqldrivers/" || cd "/plugins/sqldrivers/"; } && test $(gdb --version | sed -e 's,[^0-9]+([0-9]).([0-9]).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index ." -ex quit 'libqsqlmysql.so' && test -f libqsqlmysql.so.gdb-index && objcopy --add-section '.gdb_index=libqsqlmysql.so.gdb-index' --set-section-flags '.gdb_index=readonly' 'libqsqlmysql.so' 'libqsqlmysql.so' && rm -f libqsqlmysql.so.gdb-index || true
                                          make: [/plugins/sqldrivers/libqsqlmysql.so] Error 1 (ignored)@
                                          So, I compile in console and it finished successfully, and the result lib file is placed in needed place. I copied this file to ~/Qt/5.1.1/gcc/plugins/sqldrivers directory. Then copied it to application folder, it didn't work, then created folder named sqldrivers in application folder and copied driver file to there, not success, then made as you said, but again no success.

                                          Ok, I thougt that libmysql.dll file is libmysqlclient.so file in linux. So I changed it to libmysqlclient_r.so file, again no success.

                                          QPluginLoader did not loaded mysql driver lib file, it just said that there is a error, "Unknown error".

                                          @QSqlDatabase::drivers()@

                                          show that there is mysql driver file.

                                          @ldd libqsqlmysql.so@

                                          command in console show that all dependencies are ok for that lib file.

                                          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