[MYSQL-Qt] Create plugin MYSQL for Qt on MAC
-
Hi all,
I have just created plugin MYSQL for Qt works on Mac, but it takes much time to handle issues during creating. Therefore, this topic will give some instruction how to do that.-
Install Qt and mysql, this is info of my device and tool version
MacOs: Mojave 10.14.6
Qt : 5.13.0 (latest)
Mysql : 8.0.17 -
Default, after installation, QMYSQL haven't been installed yet, so if you try to add database from command:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
Qt would report error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7 -
So we have to install plugin and follow documentation we do this:
cd $QTDIR/Src/qtbase/src/plugins/sqldrivers
qmake -- MYSQL_PREFIX=/usr/local/mysql
make sub-mysql
Note: here we pass "/usr/local/mysql" because it's location folder of mysql after installing.
Then, we cd to mysql folder (folder inside sqldrivers) and make plugin through 2 commands
qmake
make install
After this step, in folder $QTDIR/clang_64/plugins/sqldriver would have files of libqsqlmysql like this
Now we can see info of this plugin with command:
otool -L libqsqlmysql.dylib
This is my case:
-
We can see, at version 5.13.0, Qt uses libmysqlclient.21.dylib so we have use command install_name_tool -change to link qt lib and mysql lib, this is my case:
install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/mysql-5.7.27-macos10.14-x86_64/lib/libmysqlclient.20.dylib /Users/buiquangphu/Qt5.13.0/5.13.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib -
Now, set up is done, we open qt and rebuild then run program:
If still has errors like this,
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7 -> it means QMYSQL is now available bot not loaded
You can put variable QT_DEBUG_PLUGINS = 1 in environment variable to see what happen with plugin, and this case, we got
To fix, just add environment variable:
DYLD_LIBRARY_PATH = /usr/local/mysql/lib/
and error would disappear
Problem was resolved
I am new with qt but I think this info could be useful for someone else to reduce time for searching solution.
Thanks! -
-
This helped a bunch for MacOS, do you have a similar walk through for Windows? I've been attempting with msvc and getting a:
Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
Copyright (C) Microsoft Corporation. All rights reserved.NMAKE : fatal error U1073: don't know how to make 'sub-mysql'
Stop. -
Hi @James-Hankins,
I haven't tried on Windows yet. but I think you can take a look with this post
https://forum.qt.io/topic/96506/qtdriver-not-load
May it help. -
Thanks, I was able to get the plugin built. I opened up a separate topic here:
Just sorting out now that the build of the plugin succeeded (which was due to a prompt issue on my side selecting the standard VS prompt vs the 64bit prompt) how to get my test project to use it. I've got that discussion going on within the above linked topic.
-
I am unable to run the following command:
make sub-mysqlWhy is this?
-
@emiliano23 said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:
Why is this?
Please provide more information.
What happens if you try to execute this command? -
Hi @emiliano23,
Did you install mysql on your Mac?
If installed, please check correct install path and make sure you run these command in correct directory ($QTDIR/Src/qtbase/src/plugins/sqldrivers) -
Make sure to remove the old config.cache file and qmake actually is running the config checks: https://forum.qt.io/topic/106905/what-is-current-2019-recommended-process-complete-for-building-a-mysql-driver-for-use-with-qt-on-windows/5
-
@overmatch A maybe silly question but did you call make install at the end ?
What do you get if you start the application with the QT_DEBUG_PLUGINS environment variable set to 1 ?
-
@Quang-Phu said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:
/usr/local/mysql/lib/
Brilliant, I have been beating my head against the wall on this for a week or so before finding your post. Worked like a charm...thank you so much for taking the time to share.
-
@Quang-Phu said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:
make sub-mysql
i stopped on. this he says me :
macbook@MacBook-Pro-uzivatela-Macbook sqldrivers % make sub-mysql
make: *** No rule to make target `sub-mysql'. Stop.
macbook@MacBook-Pro-uzivatela-Macbook sqldrivers %me sqldrivers folder:
-
Thanks a lot. I fixed my problem in 1hour due to this topic.