Reputation: 5274
I am trying to make a MySql-dependent app in Qt. After some time I came to know that my shared-build is not having MySql driver(by default). Can Anybody say how to get|compile it (both in shared and static).
Note: I am using Qt-4.7.2 in Windows platform
EDIT: Thanks to "vrince". This is the way he showed => I did.
1)Open qt-command prompt
2)Goto (Qt's installation path)\qt\src\plugins\sqldrivers\mysql
in my case:
D:\TempInstallationFolder\Qt\dynamic-New\qt\src\plugins\sqldrivers\mysql
3)qmake
4)make
or
mingw32-make (provided your PATH variable contains "(Qt installation path)\mingw\bin")
("make" should work if you didn't mess up with path variables. It in turn
invokes mingw32-make. I messed up this a little bit. So I invoked
mingw32-make directly.)
5)In the above command you have to indicate the mysql's "lib" path,
and "include" path through the compile flag options. Or Add those lines
in the pro file like below
INCLUDEPATH += "C:\Program Files\MySQL\MySQL Server 5.1\include"
LIBS += -L"C:\Program Files\MySQL\MySQL Server 5.1\lib\opt"
That's it. You can find the dlls in (Qt-installation path)\qt\plugins\sqldrivers
Upvotes: 5
Views: 28928
Reputation: 85
Prepare: At first mingw32 version must be installed list bellow
Build:
qmake sqldrivers.pro
cd mysql
qmake "INCLUDEPATH+=D:\\MariaDB\\ConnectorC\\include" "LIBS+=D:\\MariaDB\\ConnectorC\\lib\\libmariadb.lib" mysql.pro
If you get an error like "mysql" etc. change the mysql.pro file as below
TARGET = qsqlmysql
HEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
#QMAKE_USE += mysql
INCLUDEPATH +='D://MariaDB//include//mysql'(Check files if there isn't)
DEPENDPATH += 'D://MariaDB//include//mysql'
LIBS += -L'D://MariaDB//lib//libmysql.lib'
-llibmysql
OTHER_FILES += mysql.json
PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
include(../qsqldriverbase.pri)
qmake "INCLUDEPATH+=D:\\MariaDB\\ConnectorC\\include" "LIBS+=D:\\MariaDB\\ConnectorC\\lib\\libmariadb.lib" mysql.pro
Upvotes: 1
Reputation: 463
Building for QT5.13 using MinGW32 1. Download MySql C Connector v6.1.
> Download the MySql Installer from:
> <https://dev.mysql.com/downloads/installer/>
> Install C Connector 6.1 (Note the location we will need it later)
2. Getting QT Source Ready
> To build a plugin for QT u need to get its source. You can install it from Maintenance Tool or manually get it from github repository.
Building Plugin
Open MinGW CMD (Windows -> Start Menu -> Programs -> Qt 5.13.1 -> 5.13.1-> MinGW 7.3.0 (32-bit) -> Qt 5.13.1 (MinGW 7.3.0 32-bit) )
cd to sqldrivers path in qt source
cd D:\\QT\\Qt5.13.1\\5.13.1\\Src\\qtbase\\src\\plugins\\sqldrivers
Run qmake here. qmake sqldrivers.pro
(to create qtsqldrivers-config.pri )
cd to mysql.
cd D:\\QT\\Qt5.13.1\\5.13.1\\Src\\qtbase\\src\\plugins\\sqldrivers\\mysql
Add the plugin to the list
Once successfully build you will find qsqlmysql.dll and qsqlmysqld.dll in
the following location
D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
Copy both qsqlmysql.dll and qsqlmysqld.dll and place them in the compiler’s
plugin directory
D:\QT\Qt5.13.1\5.13.1\mingw73_32\plugins\sqldrivers
Error in Building?
Library 'mysql' is not defined.
In file cd
D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro
Commend the line QMAKE_USE += mysql
Adding Library path and Include path.
Add the following to mysql.pro at end
LIBS += -L'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib/'
-llibmysql
INCLUDEPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include'
DEPENDPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include'
QSqlDatabase: QMYSQL driver not loaded
Add the .dll files from C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib to D:\QT\Qt5.13.1\5.13.1\mingw73_32\bin
Upvotes: 9
Reputation: 2224
If you plan to rebuild Qt linked to MySQL you can stop now you don't have to ! SQL drivers are plugins (by definition dynamically loaded at run time) and can be compiled independently.
Find the driver sources in the Qt source tree somthing like qt/src/plugins/sqldrivers/mysql
then build it. The game here is to provide the proper MySQL development headers and libraries (client ones) so that the driver will build ! (Be aware if you are one windows it may be 32bits version of MySQL client you need even if you are running a 64bits OS).
You can provide MySQL path via the qmake
command for that refer to the article given by Anton, personally I copy and change the .pro
file to match my installation ... easier to rebuild later if needed.
Once the build succeeded, you will have a nice qsqlmysql.dll
you must copy into the Qt dir you use to run you apps basically something like qt/plugins/sqldrivers
in the $QT_DIR.
Upvotes: 13