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
QtWS25 Call for Papers

QSqlDatabase: QMYSQL driver not loaded / Build MySQL Plugin

Scheduled Pinned Locked Moved Solved Installation and Deployment
qmysqlsqlmoduleubuntu 14.04linux mint
32 Posts 9 Posters 39.7k 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.
  • M Offline
    M Offline
    mattewre
    wrote on last edited by A Former User
    #1

    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 http://www.qt.io/download-open-source
      Useful for unexperienced future readers:
      chmod u+x qtInstallerName.run
      ./qtInstallerName.run

    • 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
      ldd libqsqlmysql.so

    • Read this line of the output:
      libmysqlclient_r.so.16 => 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 http://doc.qt.io/qt-5/sql-driver.html documentation:
      cd /home/[yourUsername]/Qt/[QtVersion]/Src/qtbase/src/plugins/sqldrivers/mysql
      Then use the qmake provided in your Qt5.5 installation
      /home/[yourUsername]/Qt/[QtVersion]/gcc/bin/qmake
      Finally,
      make
      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/libmysqlclient.so /usr/lib/i386-linux-gnu/libmysqlclient_r.so
      sudo ln -s /usr/lib/i386-linux-gnu/libmysqlclient.so /usr/lib/i386-linux-gnu/libmysqlclient_r.so.18
      sudo ln -s /usr/lib/i386-linux-gnu/libmysqlclient.so /usr/lib/i386-linux-gnu/libmysqlclient_r.so.18.1.0

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

    • Test your application.

    1 Reply Last reply
    5
  • M Offline
    M Offline
    mattewre
    wrote on last edited by mattewre
    #2

    Other resources (not required)
    The old libmysqlclient_r.so.16
    [32bit] http://launchpadlibrarian.net/75949497/libmysqlclient16_5.1.58-1ubuntu1_i386.deb
    [64bit] http://launchpadlibrarian.net/94808408/libmysqlclient16_5.1.58-1ubuntu5_amd64.deb
    And install with sudo dpkg -i [packageName].deb


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

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

    Hi,

    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.

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

    M 2 Replies Last reply
    1
  • M Offline
    M Offline
    mattewre
    replied to SGaist on last edited by mattewre
    #4
    This post is deleted!
    1 Reply Last reply
    0
  • M Offline
    M Offline
    mattewre
    replied to SGaist on last edited by mattewre
    #5

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

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

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

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

    M 1 Reply Last reply
    0
  • M Offline
    M Offline
    mattewre
    replied to SGaist on last edited by mattewre
    #7

    @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.

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

    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.

    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
  • B Offline
    B Offline
    bionegative
    wrote on last edited by bionegative
    #9

    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 libqsqlmysql.so
    » shows its been newly built

    ldd libqsqlmysql.so
    libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (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
    [Qt]
    QPluginLoader loader;
    loader.load("TheFullFilePath");
    loader.errorString();
    » And it shows me this error: "The file '/home/..........libqsqlmysql.so' is not a valid Qt plugin.
    So something when wrong during building.

    FIXED:
    » 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..

    1 Reply Last reply
    0
  • M Offline
    M Offline
    Malhar
    wrote on last edited by
    #10

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

    Thanks

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

    Hi and welcome to devnet,

    Then, what do you see ?

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

    M 1 Reply Last reply
    0
  • M Offline
    M Offline
    Malhar
    replied to SGaist on last edited by
    #12

    @SGaist After doing ldd libqmysqlclint.so got this

    ldd libqsqlpsql.so
    linux-vdso.so.1 => (0x00007ffd58adb000)
    libpq.so.5 => /usr/lib/libpq.so.5 (0x00007f8a75afe000)
    libQt5Sql.so.5 => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007f8a758bf000)
    libQt5Core.so.5 => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007f8a75236000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f8a74f32000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8a74b6d000)
    libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f8a7490e000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f8a74533000)
    libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f8a74268000)
    libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f8a74064000)
    libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f8a73e1e000)
    libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f8a73bcd000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8a739af000)
    libicui18n.so.51 => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.51 (0x00007f8a73596000)
    libicuuc.so.51 => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.51 (0x00007f8a73210000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8a7300c000)
    libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f8a72e0a000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f8a72c02000)
    libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f8a728fa000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8a725f4000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8a723de000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f8a75f42000)
    libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f8a721af000)
    libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f8a71fa4000)
    libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f8a71da0000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f8a71b85000)
    liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f8a71976000)
    libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f8a7175b000)
    libgssapi.so.3 => /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007f8a7151d000)
    libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007f8a7125f000)
    libgcrypt.so.11 => /lib/x86_64-linux-gnu/libgcrypt.so.11 (0x00007f8a70fdf000)
    libicudata.so.51 => /opt/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.51 (0x00007f8a6f896000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f8a6f658000)
    libheimntlm.so.0 => /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007f8a6f44f000)
    libkrb5.so.26 => /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007f8a6f1c7000)
    libasn1.so.8 => /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007f8a6ef26000)
    libhcrypto.so.4 => /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007f8a6ecf3000)
    libroken.so.18 => /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007f8a6eade000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f8a6e8c5000)
    libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f8a6e6b1000)
    libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f8a6e46f000)
    libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f8a6e26a000)
    libwind.so.0 => /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007f8a6e041000)
    libheimbase.so.1 => /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007f8a6de33000)
    libhx509.so.5 => /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007f8a6dbea000)
    libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f8a6d931000)
    libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f8a6d6f8000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f8a6d4f0000)

    M 1 Reply Last reply
    0
  • M Offline
    M Offline
    Malhar
    replied to Malhar on last edited by
    #13

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

    Thanks

    1 Reply Last reply
    0
  • P Offline
    P Offline
    Peter Van Grieken
    wrote on last edited by
    #14

    @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 "libqsqlmysql.so".

    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/libqsqlmysql.so"
    QLibraryPrivate::loadPlugin failed on "/home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so" : "Cannot load library /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: (libmysqlclient_r.so.16: 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 libmysqlclient_r.so.18 located in /usr/lib/
    (note: I also have libmysqlclient_r.so.18.3.0 located in /usr/lib/ so during my frantic search for a solution I may have updated mysql again :-) ). I guess recompiling libqsqlmysql.so will link to the correct one?

    • doublechecking library dependency

    petervg@ubuntu:~/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so
    linux-vdso.so.1 => (0x00007ffc493bf000)
    libmysqlclient_r.so.16 => not found
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f5ffbe74000)
    libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f5ffbc3b000)
    libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007f5ffba21000)
    libssl.so.10 => not found
    libcrypto.so.10 => not found
    libQt5Sql.so.5 => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007f5ffb7e0000)
    libQt5Core.so.5 => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007f5ffb09a000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5ffae7b000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5ffaaf9000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5ffa7f1000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5ffa5d9000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5ffa20f000)
    libicui18n.so.54 => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.54 (0x00007f5ff9da0000)
    libicuuc.so.54 => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.54 (0x00007f5ff99f2000)
    libicudata.so.54 => /home/petervg/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.54 (0x00007f5ff7fc8000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5ff7dc4000)
    libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f5ff7bc1000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5ff79b9000)
    libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f5ff76aa000)
    /lib64/ld-linux-x86-64.so.2 (0x00005569bd500000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f5ff743c000)

    1. try to recompile libqsqlmysql.so 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 libqsqlmysql.so
    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 libqsqlmysql.so .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/libqsqlmysql.so' failed
    make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] Error 1
    petervg@ubuntu:~/Qt5.5.1/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$

    -> 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 libQt5Sql.so.5 is found in /home/petervg/Qt5.5.1/5.5/gcc_64/lib.

    1. try to recompile libqsqlmysql.so 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 libqsqlmysql.so
    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 libqsqlmysql.so .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/libqsqlmysql.so' failed
    make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] 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
    Peter

    1 Reply Last reply
    0
  • P Offline
    P Offline
    Peter Van Grieken
    wrote on last edited by
    #15

    (answering myself :-) )

    i open the mysql.pro 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 libQt5Sql.so.5 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"
      LD_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:$LD_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...

    Tnx!

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

    Hi,

    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.

    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
  • 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

  • Login

  • Search
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
  • Search

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.