Qt MySQL driver compilation process (in Windows)

Source: Internet
Author: User

 

 

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 ();
}

 

 

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.