Qt 编译 MySql 组件
安装 MySql
详见 Google
修改配置文件
打开
<path-to-qt-installed-folder>/Src/qtbase/src/plugins/sqldrivers/mysql
修改 mysql.pro
TARGET = qsqlmysql
HEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
#QMAKE_USE += mysql
OTHER_FILES += mysql.json
PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
# MySql
win32{
LIBS += -L"C:/Program Files/MySQL/MySQL Server 8.0/lib" -lmysql
INCLUDEPATH += "C:/Program Files/MySQL/MySQL Server 8.0/include"
DEPENDPATH += "C:/Program Files/MySQL/MySQL Server 8.0/include"
}
unix{
LIBS += -L/usr/lib/i386-linux-gnu/ -lmysqlclient
INCLUDEPATH += /usr/include/mysql
DEPENDPATH += /usr/include/mysql
}
include(../qsqldriverbase.pri)
修改 …/qsqldriverbase.pri
QT = core core-private sql-private
# For QMAKE_USE in the parent projects.
#include($$shadowed($$PWD)/qtsqldrivers-config.pri)
include(./configure.pri)
PLUGIN_TYPE = sqldrivers
load(qt_plugin)
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
编译生成库文件
Windows
直接使用 Qt Release 编译 mysql.pro
Ubuntu
sudo apt-get install qtbase5-private-dev
<path-to-qt-installed-folder>/<your-compile-env>/bin/qmake mysql.pro
make
拷贝生成库文件
Windows
位于 Qt 安装目录的根目录下
C:\plugins\sqldrivers
将
qsqlmysql.dll
qsqlmysqld.dll
拷贝到编译环境对应目录下
<path-to-qt-installed-folder>/<your-compile-env>/plugins/sqldrivers
Ubuntu
make install
若 Qt 没有安装在主目录下
sudo make install
chmod 777 <path-to-qt-installed-folder>/<your-compile-env>/plugins/sqldrivers/libqsqlmysql*