Qt – 如何获得编译Mysql驱动程序

我想在Qt中创build一个MySql相关的应用程序。 一段时间后,我才知道我的共享版本没有MySql驱动程序(默认情况下)。 任何人都可以说如何获得它(共享和静态)。

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

编辑:感谢“vrince”。 这是他展示的方式=>我做的。

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" 

而已。 您可以在(Qt-安装path)\ qt \ plugins \ sqldrivers中finddll

如果你打算重建链接到MySQL的Qt,你现在可以停止你不必! SQL驱动程序是插件(按定义在运行时动态加载),可以独立编译。

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

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

一旦构建成功,你将有一个很好的qsqlmysql.dll你必须复制到Qt目录,你用来运行你的应用程序基本上像qt/plugins/sqldrivers在$ QT_DIR。

Qt5的更新教程可以在这里找到: http ://seppemagiels.com/blog/create-mysql-driver-qt5-windows

另外,我没有去掉程序文件目录,而是将lib和dll复制到工作文件夹,并修改.pro文件以构建出qtcreator。

  INCLUDEPATH+=include LIBS+=$$PWD/lib/libmysql.lib 

你可以从我的git repo下载驱动程序https://github.com/Mashpy/Qt-MySQL-Driver-For-Windows