Qt 编译 MySql 组件

8 篇文章 0 订阅

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*

尽情享用吧~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值