PDA

View Full Version : Running into many problems setting up Qt and QMYSQL (qmake won't run?)



apocrita
13th June 2019, 21:31
Hello All,

I’m just starting out with Qt on Mac OSX 10.14.5 Mojave, and I’ve been having a terrible time getting past the issue “QMYSQL driver not loaded”. I know from my searching that this is something a lot of people have trouble with, and I’ve tried just about everything I found online. This morning I had to wipe everything on the computer, so I’m starting fresh without any leftovers from previous attempts. Because of this, I won't list out everything I've tried.
Here’s what I’ve done today:

-Installed MySQL Community Server 8.0.16 using the DMG installer.
-Installed Xcode via the App Store
-Installed Qt Open Source using the default installer on the qt.io downloads page; when prompted to choose components, chose under 5.12.3 “macOS” and “sources”, and left “Developer and Designer Tools” alone.

Opening up Qt Creator works fine. I opened the ‘Books’ example project and it runs fine. But, when I add the line:

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

I get the error:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

Anyway, I started to follow the guide here https://doc.qt.io/qt-5/sql-driver.html


$ cd Qt/5.12.3/clang_64/plugins/sqldrivers/
$ qmake -- MYSQL_PREFIX=/usr/local
-bash: qmake: command not found
For whatever reason qmake didn't end up on the PATH so I added it and it seemed to work:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ export PATH=$PATH:/Users/ebm/Qt/5.12.3/clang_64/bin
$ qmake --version
QMake version 3.1
Using Qt version 5.12.3 in /Users/ebm/Qt/5.12.3/clang_64/lib
but now when I try qmake -- MYSQL_PREFIX=/usr/local again, I just get the help menu.


$ qmake -- MYSQL_PREFIX=/usr/local
Usage: qmake [mode] [options] [files]

QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project
(etc)

I don't get why this is happening. I definitely got this command to execute (albeit unsuccessfully) before I had to wipe my machine, but now it isn't actually doing anything. Why not?

Any help is really appreciated. I'm totally new to all of this and I'm getting confused and kind of frustrated.

d_stranz
14th June 2019, 00:07
You probably don't actually need to build the Qt MySQL driver. It was probably installed when you installed the default Qt for MacOS. The fact that available drivers shows you that a couple of flavors of QMYSQL are available indicates that.

However, if the situation is anything like Windows, you need more than the Qt driver. You also need the MySQL client shared library on which the Qt driver depends. Available drivers only shows you that the Qt-side shared library exists. It doesn't tell you whether or not it can be fully instantiated, which means it must be able to load itself and all of the libraries it depends on. So, either the MySQL shared library wasn't installed when you installed the server, or it isn't on your PATH so isn't being loaded.

Check the MySQL site where you got the server to see if the client library is also installed, what it is named, and where it is installed. If you can't find it, then it probably wasn't installed and you need to do that. If you do find it, then make sure it is on your PATH.

Look for "Connector/C" or "Connector/C++" on the on the MySQL site.

apocrita
14th June 2019, 21:01
You probably don't actually need to build the Qt MySQL driver. It was probably installed when you installed the default Qt for MacOS. The fact that available drivers shows you that a couple of flavors of QMYSQL are available indicates that.

However, if the situation is anything like Windows, you need more than the Qt driver. You also need the MySQL client shared library on which the Qt driver depends. Available drivers only shows you that the Qt-side shared library exists. It doesn't tell you whether or not it can be fully instantiated, which means it must be able to load itself and all of the libraries it depends on. So, either the MySQL shared library wasn't installed when you installed the server, or it isn't on your PATH so isn't being loaded.

Check the MySQL site where you got the server to see if the client library is also installed, what it is named, and where it is installed. If you can't find it, then it probably wasn't installed and you need to do that. If you do find it, then make sure it is on your PATH.

Look for "Connector/C" or "Connector/C++" on the on the MySQL site.

Thanks so much for helping me!

I found in my mysql installation, under usr/local/mysql/lib, a file named "libmysqlclient.dylib" and another named "libmysqlclient.21.dylib".
Then I checked the libraries Qt is expecting:

$ otool -L libqsqlmysql.dylib
libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.12.0, current version 5.12.3)
@rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.12.0, current version 5.12.3)
/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/usr/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 20.0.0, current version 20.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
So, line 7 shows that it wants libmysqlclient.20.dylib, but I have 21. I'm guessing this is the problem (or at least part of it!) but I am not sure how to tell it to look for the version I have.
My PATH looks like this:

/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ebm/Qt/5.12.3/clang_64/bin:/usr/local/mysql/lib/


EDIT: I figured it out!

I ran


install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/mysql/lib/libmysqlclient.dylib libqsqlmysql.dylib
and now I don't get that error anymore!!

Thanks for the tip, this has been driving me up the wall for literal days :D