Windows under QT MySQL driver compilation

Source: Internet
Author: User

When using QT for MySQL database operations in a Windows environment, the following issues occur:

Qsqldatabase:qmysql driver not loadedqsqldatabase:available drivers:qsqlite QODBC3 QODBC

This is due to the fact that the MySQL database driver is not compiled under QT (to be sure, it is not compiled with Mingw32 ), and the workaround is as follows:

1. Custom install MySQL, note the installation directory do not have spaces, my directory in

5.6

Although the secondary directory has spaces, it has no effect.

2. Open qt Command Prompt and switch to directory:

3. Execute the following command:

" includepath+=c:\mysql\mysql Server 5.6\include " " libs+=c:\mysql\mysql Server 5.6\lib\libmysql.lib " Mysql.pro

Note that the above directory is related to the installation of MySQL version, I use the version is:

Mysql-installer-community-5.6.26.0.msi

4. Implementation

Mingw32-make

The following error may appear here:

In file included fromMain.cpp: -:../.. /.. /sql/drivers/mysql/qsql_mysql.h: the: +: Error:mysql.h:no such file or directory in file included fromMain.cpp: -:../.. /.. /sql/drivers/mysql/qsql_mysql.h:108: error:expected')'Before'*'Tokenmingw32-make[1]: * * * [TMP/OBJ/DEBUG_SHARED/MAIN.O] Error1Mingw32-make[1]: Leaving directory ' c:/qt/2010.02.1/qt/src/plugins/sqldrivers/mysql'Mingw32-make: * * * [Debug-all] Error2

This is caused by not including the MySQL library file, add the following code in the Mysql.pro file:

" c:/mysql/mysql Server 5.6/include "  "c:/mysql/mysql Server 5.6/lib/libmysql.lib"

Repeat step 4 to generate the following 4 files:

qsqlmysql4.dlllibqsqlmysql4.aqsqlmysqld4.dlllibqsqlmysqld4.a

5. Copy libmysql.lib from C:\MySQL\MySQL Server 5.6\lib\ to C:\Qt\2010.05\mingw\bin.

End of text

Reference:

1. http://blog.csdn.net/wang_xuehen/article/details/7483133

2. http://blog.csdn.net/wang19870102/article/details/39318225

3. http://www.cppblog.com/biao/archive/2011/10/29/159296.html

Windows under QT MySQL driver compilation

Related Article

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.