I. preparation phase
1. first install QT Creator: qt-creator-win-opensource-2.1.02. re-install QT Library: qt-win-opensource-4.7.2-mingw (installed QT library, will ask the mingw compiler Directory: D: \ QT \ qtcreator-2.1.0 \ mingw) 3. add system environment variable: D: \ QT \ 4.7.2 \ bin; D: \ QT \ qtcreator-2.1.0 \ mingw4. complete, start QT Creator as follows:
5. Install MySQL. Mysql-5.1.56-win32
Note: During MySQL installation, You must select Custom installation m and check all the options (complete installation ).
Finally, modify the installation path: My installation path is as follows: D:/MySQL
After the installation, libmysql. dll is in the bin directory under D:/MySQL, libmysql. Lib is in the LIB/OPT directory under D:/MySQL, And the header file is in the include directory.
6. Set the PATH environment variable: D:/MySQL/bin;
7. You also need to download a dynamic library format conversion tool:
Bytes
2. Steps
1. Generate the libmysql. A file from libmysql. Lib (the static link file used by mingw is in Linux format *.)
> Cd MySQL/lib/OPT
> Reimp-D libmysql. Lib (generate the libmysql. Def file)
> Dlltool-K-D libmysql. Def-l libmysql. A (generate the libmysql. A file)
2. After Entering the D:/QT/4.7.2/src/plugins/sqldrivers/MySQL directory, add the following lines in the mysql. Pro file:
Export depath + = D:/MySQL/include
Libs + = D:/MySQL/lib/opt/libmysql. Lib
Qt + = SQL
3. Generate the MySQL driver in QT
> Cd D:/QT/4.7.2/src/plugins/sqldrivers/MySQL
> Qmake-O makefile mysql. Pro
(A warning will be reported, but compilation will not be affected)
> Make
4. copy the libqsqlmysqld4.a and qsqlmysqld4.dll files under the D:/QT/4.7.2/src/plugins/sqldrivers/MySQL/DEBUG directory to the D:/QT/4.7.2/plugins/sqldrivers directory.
5. Verify that after creating a new project, you need to add QT ++ = SQL IN THE helloc. Pro project file
# Include
<Qtgui/qapplication>
# Include
<Qtsql/qsqldatabase>
Int main (INT argc, char * argv [])
{
Qcoreapplication A (argc, argv );
Qsqldatabase DB = qsqldatabase: adddatabase ("qmysql"); // Add a database driver
Return a.exe C ();
}