Qt-MySQL database driver compilation (MSVC)

Source: Internet
Author: User
Qt-MySQL database driver compilation (MSVC) Note:In versions earlier than Qt5.2, the databases provided include ODBC, SQLite, and PSQL. others that are not provided need to be compiled by themselves. However, MySQL has been included since Qt5.2 and does not need to be compiled manually. However, to illustrate how to use MySQL, the usage of each version is compared and described here.

Qt5.2

To install Qt5.2, you can view it under the installation directory pluins/sqldrivers. the bread contains the MySQL driver.


Versions earlier than Qt5.2

MySQL versions earlier than MySQL 5.2 need to be compiled by yourself. Here we take MySQL 5.2 as an example (the same for other versions ).

For information about the Database driver and how to compile it, see The Qt Assistant, which contains the section: SQL Database Drivers.


The following describes how to use MSVC to compile MySQL.

Environment: VS2010 + Qt5.2

In fact, the version issue has no major impact, because the compilation is similar...

1. download the Qt installation package and Qt plug-in

  • Qt-windows-opensource-5.2.0-msvc2010_opengl-x86-offline.exe
  • Qt-vs-addin-1.2.2-opensource.exe

See VS to build an integrated Qt environment.

Note:Remember to select the source code when installing opensource. Otherwise, you have to download it again during compilation.

II. download MySQL
  • MySQL home: http://www.mysql.com /.

(1) go to the homepage and select Downloads (GA)

As follows:

(2) go to the bottom of the page, MySQL Community Edition (GPL), and select: Download from MySQL Developer Zone>

As follows:


(3) go to the upper-right corner of the page and select the version corresponding to New Releases (5.6 is selected here)

As follows:

(4) go to the bottom of the page, Other Downloads, and select the corresponding version (here I select 32 bits)

As follows:

After the download is complete, decompress it and copy it to a specified path (I chose: D:/mysql-5.6.15-win32 ).

III. Compilation

(1) Choose Start> All Programs> Qt5.2.0> Qt5.2.0> MSVC 2010 OpenGL> Qt5.2.0 for Desktop (MSVC 2010 OpenGL)

As follows:

(2) go to the Qt source code directory. my directory is D:/Software/Qt/Qt5.2.0/5.2.0/Src/qtbase/src/plugins/sqldrivers/mysql.

(3) execute the command: qmake "INCLUDEPATH + = D:/mysql-5.6.15-win32/include" "LIBS + = D:/mysql-5.6.15-win32/lib/libmysql. lib" mysql. pro

As follows:

After the execution is complete, the Makefile file is generated.

As follows:

(4) choose start> All Programs> Microsoft Visual Studio 2010> Visual Studio Tools> Visual Studio command prompt (2010)

As follows:

(5) execute the command: nmake

As follows:


(6) prepare the environment

Copy the generated qsqlmysql. dll and qsqlmysqld. dll to the D:/Software/Qt/Qt5.2.0/5.2.0/msvc2010_opengl/plugins/sqldrivers directory.

Copy libmysql. dll and libmysqld. dll under the MySQL Directory (D:/mysql-5.6.15-win32/lib) to the D:/Software/Qt/Qt5.2.0/5.2.0/msvc2010_opengl/bin directory.

Well, it's done here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.