Adding MySQL driver to Qt
-
Hello,
I am trying to connect to a MySQL Database using Qt (5.12.5) on macOS 10.15.
I have the MySQL community Server installed (https://dev.mysql.com/downloads/mysql/).
Therefore the libmysqlclient.dylib is available in /usr/local/mysql-8.0.18-macos10.14-x86_64/lib/libmysqlclient.dylibHowever I get the following error, when trying to compile my project:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
I tried to head to /Users/USERNAME/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/mysql and run qmake. This resulted in the following error
Cannot read /qtsqldrivers-config.pri: No such file or directory /Users/USERNAME/Qt/5.12.5/clang_64/mkspecs/features/qt_plugin.prf:59: Cannot write file /mkspecs/modules-inst/qt_plugin_qsqlmysql.pri: Cannot create parent directory
I am an absolute noob to qt and have no idea what to do from here.
Could you explain me what I have to do in order to get the MySQL driver running?Thank you so much!
-
These are the instruction that I made after installed it on my Ubuntu 18.04 linux install. Maybe it will help you
Download QT 5.12.4 from QT website using the downloads buttons and then select open source and downloadAfter Download is complete go to Downloads folder and run the installer
(for new ubuntu users – right click on file in downloads and select permissions and select option at bottom)Download latest QT that is known to have LTS (long term support)
-Run installer
-deselect android stuff and make sure that you select the dev tools and sources at the bottom
install QTdownload and install mysql and dev packages
sudo apt-get install libglu1-mesa-dev
sudo apt-get install build-essential
sudo apt-get install libmysqlclient-dev
sudo apt-get install libssl-devnavigate to your Qt folder/5.12.4/Src
-run config file
-./configure -plugin-sql-mysqlNavigate to qt source ie...Qt/5.12.4/Src/qtbase/src/plugins/sqldrivers/mysql
-run the QT qmake
/home/bj/Qt/5.12.4/gcc_64/bin/qmake MYSQL_PREFIX=/usr/include/mysql/ mysql.prolocations may vary depending on where you installed Qt during the installation process and what version of Ubuntu you may be using
after running qmake
-run make
-make installyou should be set from here...if you have any more issues then refer to these articles to seek clarification
https://forum.qt.io/topic/59449/qsqldatabase-qmysql-driver-not-loaded-build-mysql-plugin
https://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-4-and-higher
https://forum.qt.io/topic/36072/qmysql-driver-not-loaded-on-ubuntu/15