qt mysql driver_QT mysql driver

(本文转自网络)

Create MySQL driver for Qt5 on Windows

Posted on 19 February 2013 - 14:24

This tutorial explains how to create the MySQL driver for Qt5 on Windows using MinGW. If you are looking for the tutorial to do this with Qt4, click here.

Step 1

Download all the needed software.

Qt (libraries and source code)

This are twoseparate files! E.g. qt-windows-opensource-5.0.1-mingw47_32-x86-offline.exe and qt-everywhere-opensource-src-5.0.1.zip

MySQL Community Server (E.g. mysql-5.5.30-win32.msi)

I didn't use version 5.6 because the .msi only allowed me to install the 64-bit version of the Client C API Library, which apparently gives errors later in the tutorial. So make sure you get the 32-bit verison! If you really want version 5.6, an option might be to download the 32-bit version of the source files and use those. Note that I didn't test this option, so I can't help you with that.

Step 2

Install the downloaded software.

Install Qt, the components I installed are the default ones. (See image 1)

Install MySQL, you only need to install the Client C API Library the other components are optional for this tutorial. (See image 2)

I installed it under C:\Program Files (x86)\MySQL\MySQL Server 5.5. Since the path contains spaces, you should useC:\PROGRA~2\MySQL\MYSQLS~1.5, else it won't work. 1

Extract the Qt Sources to a folder of your choosing. I placed it in the folder Qt was installed into. (C:\Qt\Qt5.0.1)

I also renamed the extracted folder to Sources instead of the long qt-everywhere-opensource-src-5.0.1 name.

2532d3aca114461b9a2ba9452742df03.pngImage 1: Install Qt

83c0844291ba44e0ff7805be41b1c0d3.pngImage 2: Install MySQL

Step 3

Open the Qt Command Prompt. (See image 3)

Start > All Programs > Qt 5.0.1 > 5.0.1 > MinGW 4.7 > Qt 5.0.1 for Desktop (MinGW 4.7)

Picasa Content Image 3: Qt

Command Prompt

Step 4

Run the following commands (change them according to your environment):

set mysql=C:\\PROGRA~2\\MySQL\\MYSQLS~1.5

cd C:\Qt\Qt5.0.1\Sources\qtbase\src\plugins\sqldrivers\mysql\

qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro

mingw32-make

Step 5

Picasa Content

Copy qsqlmysql.dll and qsqlmysqld.dll from C:\Qt\Qt5.0.1\Sources\qtbase\plugins\sqldrivers toC:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\sqldrivers.

Step 6

Copy libmysql.dll from %mysql%\lib to C:\Windows

Finished

That's all, but don't forget to add QT += sql to your project file, else it won't work. To check which drivers are available run this program. You can also download the code as a Qt project in the attachments.

#include

#include

int main(int argc, char *argv[])

{

qDebug() << QSqlDatabase::drivers();

return a.exec();

}

1Note: For 32-bit systems the install path of MySQL will be C:\Program Files\MySQL\MySQL Server 5.5 and the path without spaces will beC:\PROGRA~1\MySQL\MYSQLS~1.5.To determine a custom path without spaces, use the

Attachments:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值