Qt - 如何获取|编译Mysql驱动程序

Qt - How to get|compile Mysql driver(Qt - 如何获取|编译Mysql驱动程序)

本文介绍了Qt - 如何获取|编译Mysql驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Qt 中制作一个依赖于 MySql 的应用程序.一段时间后,我才知道我的共享构建没有 MySql 驱动程序(默认情况下).任何人都可以说如何获取|编译它(共享和静态).

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).

注意:我在 Windows 平台上使用 Qt-4.7.2

Note: I am using Qt-4.7.2 in Windows platform

感谢vrince".这就是他展示的方式 => 我做到了.

Thanks to "vrince". This is the way he showed => I did.

 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)mingwin")

   ("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-安装路径)qtpluginssqldrivers

That's it. You can find the dlls in (Qt-installation path)qtpluginssqldrivers

推荐答案

如果您计划重建链接到 MySQL 的 Qt,您现在可以停止,您不必这样做!SQL 驱动程序是插件(根据定义在运行时动态加载)并且可以独立编译.

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.

在 Qt 源代码树中查找驱动程序源代码,例如 qt/src/plugins/sqldrivers/mysql 然后构建它.这里的游戏是提供正确的 MySQL 开发头文件和库(客户端的),以便驱动程序构建!(请注意,如果您是一个 Windows,即使您运行的是 64 位操作系统,它也可能是您需要的 32 位版本的 MySQL 客户端).

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).

您可以通过 qmake 命令提供 MySQL 路径,参考 Anton 给出的文章,我个人复制并更改 .pro 文件以匹配我的安装... 如果需要,以后更容易重建.

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.

一旦构建成功,您将拥有一个不错的 qsqlmysql.dll,您必须将其复制到用于运行应用程序的 Qt 目录中,基本上类似于 qt/plugins/sqldrivers 在 $QT_DIR 中.

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.

这篇关于Qt - 如何获取|编译Mysql驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Qt - 如何获取|编译Mysql驱动程序

基础教程推荐