Use tdm to compile the 64-bit qt mysql driver, tdmqt
The official website only provides the 32-bit qt version compiled by mingw. After testing, the mysql driver can be directly installed and transactions can be executed.
However, if I use the 64-bit tdm-gcc qt compiled by myself, I will not be able to enjoy this benefit.
The procedure is as follows:
Http://1029975378-qq-com.iteye.com/blog/1310910
Http://blog.sina.com.cn/s/blog_74a7e56e01017s64.html
==================== Step 1 ==========================
The first step is to generate the def file and prepare the header file required for mysql compilation.
Go to the mysql official website to download the zip installation package (64-bit version, 5.6.26 is 349.4 M ):
Http://dev.mysql.com/downloads/mysql/
Decompress and copy the lib file from the following path to the E: \ Coding \ QT \ SourceCode \ mysql_svr \ x64 \ lib \ folder.
Mysql-5.6.26-winx64 \ lib \ libmysql. lib
Copy the include file from the decompressed file to the E: \ Coding \ QT \ SourceCode \ mysql_svr \ x64 \ include \ folder.
Next, use libmysql. lib extracted by reimp to generate the libmysql. def file. reimp only has 32bit, but it can also be used to process 64bit lib files,
Go to the E: \ Coding \ QT \ SourceCode \ mysql_svr \ x64 \ lib \ folder and run the following command:
C: \ Qt \ Qt5.5.0 \ Tools \ mingw__32 \ bin \ reimp-d libmysql. lib
**************************************** **************************************** *****
** Insert a sentence
** You can also find the libmysql. def file in the mysql source code below. The download path of the source code (5.6.26 is 39.6 M) is as follows ):
** Http://dev.mysql.com/downloads/mysql/
** The downloaded zip file is decompressed. The path is as follows:
** Mysql-5.6.26 \ libmysql. def
** After my actual operations, the driver generated using the def file in the source code does not support transaction operations.
** In addition, the latest mysql uses cmake to configure the project,
** The method mentioned below may be used to compile mysql Source Code directly using qt, but I have not tried it.
** Http://www.2cto.com/kf/201401/272101.html
**************************************** **************************************** *****
==================== Step 2 ========================
Generate the libmysql. a file from libmysql. def obtained in step 1.
C: \ TDM-GCC-64 \ bin \ dlltool-k-d libmysql. def-l libmysql.
Then go to the following qt source code directory (the premise of the following operation is that you have used the configure command to configure the tdm-gcc-64 to compile the entire qt code, because it involves many other configuration files)
E: \ Coding \ QT \ SourceCode \ qt-everywhere-opensource-src-5.5.0 \ qtbase \ src \ plugins \ sqldrivers \ mysql
Modify the mysql. pro file and insert lib and include information at the beginning. The modified file is roughly as follows:
***************************
TARGET = qsqlmysql
LIBS * = "E: \ Coding \ QT \ SourceCode \ mysql_svr \ x64 \ lib \ libmysql."
Export depath * = "E: \ Coding \ QT \ SourceCode \ mysql_svr \ x64 \ include"
SOURCES = main. cpp
OTHER_FILES + = mysql. json
Include (.../../SQL/drivers/mysql/qsql_mysql.pri)
PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
Include (../qsqldriverbase. pri)
***************************
Use qmake to generate makefile from the pro file. The command is as follows:
C: \ Qt \ Qt5.5.0/5.5 \ tdm510_shared \ bin \ qmake-o Makefile mysql. pro
Run the following command to generate the mysql driver file of qt:
C: \ TDM-GCC-64 \ bin \ mingw32-make
The generated file (qsqlmysql. dll, qsqlmysqld. dll) is in the following directory:
E: \ Coding \ QT \ SourceCode \ qt-everywhere-opensource-src-5.5.0 \ qtbase \ plugins \ sqldrivers
==================== Step 3 ============================
Copy the two generated files (qsqlmysql. dll, qsqlmysqld. dll) to the following path of the corresponding qt
C: \ Qt \ Qt5.5.0 \ 5.5 \ tdm510_shared \ plugins \ sqldrivers
==================== Step 4 ==========================
The following error may still occur when compiling and running your program.
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QODBC3 qodbc qsqlite qmysql QMYSQL3
Use the following mysql zip package files downloaded in Step 1:
Mysql-5.6.26-winx64 \ lib \ libmysql. dll
Copy libmysql. dll to the bin folder of qt.
C: \ Qt \ Qt5.5.0 \ 5.5 \ tdm510_shared \ bin
OK. Now you can use qt to connect to the mysql database.
==========================================