QMYSQL Driver not loaded but available
Hello, I am having problems building the QMYSQL plugin. I've read a number of forum posts and tried a bunch of solutions, but have not had any luck. Here is some background information:
Here is the code I'm using to connect to the database:
db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("host"); db.setUserName("name"); db.setPassword("password"); db.setDatabaseName("dbName"); bool ok = db.open();
Results of locate mysqlclient command
/home/seth/libmysqlclient-dev_5.7.20-1ubuntu17.04_amd64.deb /home/seth/libmysqlclient20_5.7.20-1ubuntu17.04_amd64.deb /usr/lib/x86_64-linux-gnu/libmysqlclient.a /usr/lib/x86_64-linux-gnu/libmysqlclient.so /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20.3.7 /usr/lib/x86_64-linux-gnu/pkgconfig/mysqlclient.pc /usr/share/doc/libmysqlclient-dev /usr/share/doc/libmysqlclient20 /usr/share/doc/libmysqlclient-dev/COPYING.gz /usr/share/doc/libmysqlclient-dev/README /usr/share/doc/libmysqlclient-dev/changelog.Debian.gz /usr/share/doc/libmysqlclient-dev/copyright /usr/share/doc/libmysqlclient20/COPYING.gz /usr/share/doc/libmysqlclient20/README /usr/share/doc/libmysqlclient20/changelog.Debian.gz /usr/share/doc/libmysqlclient20/copyright /usr/share/lintian/overrides/libmysqlclient-dev /usr/share/lintian/overrides/libmysqlclient20 /var/cache/apt/archives/libmysqlclient-dev_5.7.20-1ubuntu16.04_amd64.deb /var/cache/apt/archives/libmysqlclient20_5.7.20-1ubuntu16.04_amd64.deb /var/lib/dpkg/info/libmysqlclient-dev.list /var/lib/dpkg/info/libmysqlclient-dev.md5sums /var/lib/dpkg/info/libmysqlclient20:amd64.list /var/lib/dpkg/info/libmysqlclient20:amd64.md5sums /var/lib/dpkg/info/libmysqlclient20:amd64.shlibs /var/lib/dpkg/info/libmysqlclient20:amd64.triggers
Results of ldd libqsqlmysql.so in the qt plugins directory:
linux-vdso.so.1 => (0x00007ffca2ac6000) libQt5Sql.so.5 => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007ff6a5df1000) libQt5Core.so.5 => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007ff6a56a3000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff6a5469000) libmysqlclient.so.18 => not found libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff6a50e7000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff6a4ddd000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff6a4bc7000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff6a47fd000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff6a45e2000) libicui18n.so.56 => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.56 (0x00007ff6a4149000) libicuuc.so.56 => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.56 (0x00007ff6a3d91000) libicudata.so.56 => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.56 (0x00007ff6a23ad000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff6a21a9000) libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007ff6a1fa7000) libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff6a1c95000) /lib64/ld-linux-x86-64.so.2 (0x000055e8a1956000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007ff6a1a25000)
Other things I've tried:
Running qmake from the terminal as such:
~/Qt/5.10.0/Src/qtbase/src/plugins/sqldrivers/mysql$ qmake "INCLUDEPATH+=/usr/include" "LIBS+=-L/usr/lib/x86_64-linux-gnu/lib -lmysqlclient_r" mysql.pro ``
Cannot read /home/seth/Qt/5.10.0/Src/qtbase/src/plugins/sqldrivers/qtsqldrivers-config.pri: No such file or directory
I'm basically stumped at this point, and fairly frustrated. I feel like the documentation around building sql plugins is very lacking. Any ideas or different approaches to solving this problem are greatly appreciated!
Hi and welcome to devnet,
As you could see you have version 20 of the client library while the Qt plugin was built against 18.
IIRC, with the latest changes that happened to the build system, you have to do a full configure run (no need to build all of Qt at all) and then you should be able to build the plugin by hand.
I recommend doing that out of source so you can nuke everything if something goes wrong and try again.
Thanks for the fast response. Can you give further details on some of your instructions, as I'm very new to Qt programming and programming in general, so still learning how to configure dependencies.
- How do I do a "full configure run"? From the command line, within Qt? What commands do I need to run, and how do I make sure Qt is configured to work with version 20 of the client library?
- I'm not quite sure what you mean by "build the plugin by hand." I've seen the documentation here, but to be honest I've found it quite unclear as a novice user how to build a plugin from this documentation, and I have a sense there may be some pre-requisites which I'm missing. If you could give a step-by-step on how to build the plugin from hand, I wold really appreciate it!
- Last one! What do you mean by "out of source"? I've read the term "Qt source" thrown around quite a bit on forums, but have not been able to find a clear, consistent definition. Any clarity here would be great!
- Download Qt's sources,
- Install the MySQL dev package from your distribution package manager
- Call the configure script from the qtbase module (do it out of source)
See number 1 and then you can go on and build directly the plugin
Literally what the expression means: not in the same folder as your source code.
mkdir build_qtbase pushd build_qtbase /path/to/qtbase/configure make popd
That's how you do an out of source build of Qt (minus the installation step)
@SGaist When you say Download Qt's sources, do you literally mean the source code? I.e --> https://doc-snapshots.qt.io/qt5-5.9/linux-building.html
Why does the download that I have not work? Also, I believe I have already installed the MySQL dev package. Not trying to be difficult here, would just like to understand!
I believe I am making progress. Found a good resource. Here's a more open-ended question: how would one know they needed to compile Qt from source code in order to use MySQL? It's definitely not spelled out anywhere in the documentation that I could find, and it's taken me the better part of a week (off and on) to troubleshoot it. Is this just a weird edge-case that doesn't happen often, or is the standard way that all development packages should be installed to ensure dependencies are met?
OK, I followed the instructions here and it looks like everything built correctly. However, when I now try to build the plugin in the terminal using:
seth@seth-XPS-L521X:~/qt-everywhere-src-5.10.0/qtbase/plugins/sqldrivers$ qmake "INCLUDEPATH+=/usr/include" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r" mysql.pro
I get the message:
Cannot find file: mysql.pro.
No there is not. In fact, I can't find a MySQL.pro file anywhere on my system. Is this a file I need to create?
Do I need to explicitly call qmake from the qt-everywhere-src-5.10.0 folder?
It should be in
qtbase/src/plugins/sqldrivers/mysql/. If not then you should consider re-downloading the sources.
It is not there. How do I ensure that it is there when I re-download the sources?
- Download the sources
- Un-compress the archive
- Take a look in the folder mentioned before
OK, but what if the mysql.pro file is not in the folder above? I ask because since I will be downloading the same archive as I used earlier, that has led me to the problem of the mysql.pro file not being there. I assume this will be the case again. If this is the case, how to I obtain sources that contain the proper files for making the plugin with mysql?
Where did you get the sources from ?
I downloaded the tar.xz archive from https://www1.qt.io/offline-installers/
Here's a more open-ended question: how would one know they needed to compile Qt from source code in order to use MySQL?
Just to be clear: You do not have to compile Qt from source code to use MySQL (or almost anything else). You have to because you are choosing the latest Qt release, 5.10.
Instead, you are using Ubuntu 16.04, you could accept the pre-compiled packages, available through standard
apt-get, for the version of Qt that was current at the time 16.04 was released. I think that was Qt 5.5., BTW.
For example, I use Ubuntu 17.04 now, and the
apt-getpackage gives me Qt 5.7.1. Similarly, I use whatever the version of MySQL was for 17.04. I have not fetched a line of source code or done any compiling at all. And thankful for that!
When 18.04 comes out, I will do same, upgrading to whatever versions of Qt & MySQL are available then through
So it in part depends on whether you need the latest version of Qt or not.
@JonB Thank you for the clarification! That makes a ton more sense. I was beginning to wonder why connecting to a database is seemingly giving so many people so much trouble!
I've actually figured out a different way to solve the problem by using C++ MySQL Connector libraries provided by Oracle, and have gotten it working in my application! I will also try using the Qt and MySQL versions provided by my Ubuntu release and see how that goes.