Qt-如何获取|编译Mysql驱动程序
Qt - How to get|compile Mysql driver
我正试图在Qt中制作一个依赖MySql的应用程序。过了一段时间,我才知道我的共享构建没有MySql驱动程序(默认情况下)。任何人都能说出如何获得|编译它(共享和静态)吗。
注意:我在Windows平台中使用Qt-4.7.2
编辑:感谢"vrince"。这就是他表现出来的=>我做到了。
1)Open qt-command prompt
2)Goto (Qt's installation path)qtsrcpluginssqldriversmysql
in my case:
D:TempInstallationFolderQtdynamic-Newqtsrcpluginssqldriversmysql
3)qmake
4)make
or
mingw32-make (provided your PATH variable contains "(Qt installation path)mingwbin")
("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 FilesMySQLMySQL Server 5.1include"
LIBS += -L"C:Program FilesMySQLMySQL Server 5.1libopt"
就是这样。你可以在(Qt安装路径)\Qt\plugins\sqldrivers
如果您计划重建链接到MySQL的Qt,现在就可以停止了!SQL驱动程序是插件(根据定义,在运行时动态加载),可以独立编译。
在Qt源代码树中找到驱动程序源代码,比如qt/src/plugins/sqldrivers/mysql
,然后构建它。这里的游戏是提供合适的MySQL开发头和库(客户端的),以便构建驱动程序!(请注意,如果你是一个windows,即使你运行的是64位操作系统,你也可能需要32位版本的MySQL客户端)。
你可以通过qmake
命令提供MySQL路径,参考Anton的文章,我个人复制并更改了.pro
文件以匹配我的安装。。。如果需要,以后更容易重建。
一旦构建成功,您将获得一个不错的qsqlmysql.dll
,您必须将其复制到用于运行应用程序的Qt目录中,基本上类似于$Qt_dir中的qt/plugins/sqldrivers
。
使用MinGW32为QT5.13构建1.下载MySql C连接器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.获取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.
构建插件
打开MinGW CMD(Windows->开始菜单->程序->问题5.13.1->5.13.1->MinGW 7.3.0(32位)->Qt 5.13.1(MinGW 7.3.032位)
qt源中cd到sqldrivers的路径
cd D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers
在此处运行qmake。
qmake sqldrivers.pro
(用于创建qtsqldrivers-config.pri)cd到mysql。
cd D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql
- 在此处运行qmake。qmake mysql.pro
将插件添加到列表
一旦成功构建,您将在中找到qsqlmysql.dll和qsqlmysqld.dll以下位置
D:QTQt5.13.15.13.1Srcqtbasesrcpluginssqldriverspluginssqldrivers
复制qsqlmysql.dll和qsqlmysqld.dll,并将它们放在编译器的插件目录
D:QTQt5.13.15.13.1mingw73_32pluginssqldrivers
建筑错误?
未定义库"mysql"。
在文件cd中
D:QTQt5.13.15.13.1Srcqtbasesrcpluginssqldriversmysqlmysql.pro
启用线路
QMAKE_USE += mysql
正在添加库路径和包含路径。
在末尾将以下内容添加到mysql.pro中
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驱动程序未加载
将C:\Program files(x86)/MySQL/MysQLConnector C 6.1/lib中的.dll文件添加到D:\QT\Qt5.13.1\5.13.1\mingw73_32\bin
准备:首先必须在下面的列表中安装mingw32版本
- MariaDB连接器32位(这很重要)
- 已安装Mingw32
构建:
- 打开mingw32 make
- 转到";C: \Qt\Qt5.12.9\5.12.9\src\qtbase\src\plugins\sqldrivers"(英寸我的驱动器)
- 在mingw32终端>
qmake sqldrivers.pro
- 之后
cd mysql
- 在mingw32终端>
qmake "INCLUDEPATH+=D:\MariaDB\ConnectorC\include" "LIBS+=D:\MariaDB\ConnectorC\lib\libmariadb.lib" mysql.pro
如果你得到一个错误,如";mysql";等更改mysql.pro文件如下
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)
- 然后在mingw32终端中再次制作>
qmake "INCLUDEPATH+=D:\MariaDB\ConnectorC\include" "LIBS+=D:\MariaDB\ConnectorC\lib\libmariadb.lib" mysql.pro
- 二叉排序树无法编译
- 致命错误mysql.h:编译期间没有这样的文件或目录
- Mysql++ 简单脚本编译失败
- 在Linux环境下用MYSQL.h编译C++程序
- #include < mysql.h> & #include <my_global.h> 导致编译错误
- 从C++连接MySQL时程序错误中"error: stray ‘302’"编译错误
- 在windows 7 64位中编译Qt 4.8.0的MySQL驱动程序
- 使用Visual Studio 2015 Win64编译MySQL连接器
- 编译MySQL连接器/C++的examples/standalone_example.cpp失败
- Qt编译问题w/ MySQL - Mac OS X
- 使用 MINGW32 在 Debian 上使用 C++ 和 MySQL 进行编译
- 如何定位MySQL头文件来编译qt
- 编译并运行文件夹中提供的MySQL++和C++示例
- 为什么简单的mysql++代码编译独立,而不是在项目
- "cannot create .moc/main.moc "有一个错误,当我编译Qt5.7的mysql驱动程序时
- 编译mysql连接器c++与mingw,编译错误
- Qt-如何获取|编译Mysql驱动程序
- 无法编译mysql源代码
- 使用MySQL支持编译QuickFIX C++
- 在Cygwin中使用MySQL编译c++应用程序