[MYSQL-Qt] Create plugin MYSQL for Qt on MAC
-
wrote on 4 Sept 2019, 17:27 last edited by Quang Phu 9 Apr 2019, 17:30
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! -
-
wrote on 16 Sept 2019, 01:22 last edited by
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. -
wrote on 17 Sept 2019, 02:50 last edited by Quang Phu
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. -
wrote on 21 Sept 2019, 16:21 last edited by
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.
-
wrote on 2 Oct 2019, 04:46 last edited by
I am unable to run the following command:
make sub-mysqlWhy is this?
-
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? -
@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?wrote on 2 Oct 2019, 23:30 last edited by@jsulm
After running with success
qmake -- MYSQL_PREFIX=/usr/local/mysql
I execute the command
make sub-mysqlAnd the output is
make: *** No rule to make target `sub-mysql'. Stop. -
wrote on 3 Oct 2019, 00:52 last edited by Quang Phu 10 Mar 2019, 06:11
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
-
wrote on 9 Nov 2019, 16:05 last edited by
i tried, and almost every step is absolutely like yours, but at last step, i still get "drivers not loaded"
-
i tried, and almost every step is absolutely like yours, but at last step, i still get "drivers not loaded"
@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 ?
-
wrote on 1 May 2020, 10:01 last edited by
@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.
-
wrote on 26 Aug 2020, 13:40 last edited by Imon
Could anyone tell me where/how to add the environment variable"DYLD_LIBRARY_PATH"??
I am using qt5.14.2 and I couldn’t figure out how to add it -
Could anyone tell me where/how to add the environment variable"DYLD_LIBRARY_PATH"??
I am using qt5.14.2 and I couldn’t figure out how to add it@Imon hi and welcome to devnet,
If using Qt Creator, go to the Run part of the Project panel.
-
@Imon hi and welcome to devnet,
If using Qt Creator, go to the Run part of the Project panel.
-
wrote on 27 Aug 2020, 09:44 last edited by Eternus
@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 % -
@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:
@Eternus you are already getting answered in your thread. Please don't pile up in other threads.
-
wrote on 24 Feb 2021, 12:58 last edited by
Thanks a lot. I fixed my problem in 1hour due to this topic.
-
i tried, and almost every step is absolutely like yours, but at last step, i still get "drivers not loaded"
wrote on 5 Apr 2021, 15:28 last edited by@overmatch have you solve this problem ,i have the same problem
-
wrote on 29 Sept 2022, 20:12 last edited byThis post is deleted!