Qt4.8 compile the MySQL driver

Source: Internet
Author: User

Http://qimo601.iteye.com/blog/1654429

1. First, go to the corresponding QT/src/plugins/sqldrivers/MySQL directory (my directory is: C: \ QT \ 4.8.0 \ SRC \ plugins \ sqldrivers \ mysql), which contains two files: MySQL. pro, a main. CPP also has a readme

2. Open the mysql. Pro file in the directory in a text editor and add the following to MySQL. Pro:

Export depath + = "C: \ Program Files \ mysql server 5.5 \ include"

Libs + = "C: \ Program Files \ mysql server 5.5 \ Lib \ libmysql. lib"

Save and exit (that is, the include path of your MySQL and the libmysql. Lib path of OPT under Lib)

3. Open QT 4.8.0 command prompt and compile the file.

# Qmake-O makefile mysql. Pro

// Three warning messages are displayed, but the alarm is not affected.

# Mingw32-make (this network has several compilation commands, I use nmake );

4. Then you will find the QT/plugins/sqldrivers path under your QT (my path is under s: \ QT \ 4.8.0 \ plugins \ sqldrivers) the following four files are added: libqsqlmysql4.a, libqsqlmysqld4.a, qsqlmysql4.dll, and qsqlmysqld4.dll (the generated file is not necessarily the above four files). Then the compilation is successful and MySQL can be used! ~

5. For security, copy the libmysql. dll file in the bin file under MySQL to system32.

#include <QtGui>#include <QtSql>#include <cstdlib>#include <QtGui/QApplication>#include <QtSql/QtSql>bool createConnection(){    qDebug() << "Available drivers:";    QStringList drivers = QSqlDatabase::drivers();    foreach(QString driver, drivers)              qDebug() << "\t" << driver;    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");    qDebug() << "MYSQL driver valid?" << db.isValid();}int main(int argc, char *argv[]){    QApplication a(argc, argv);    MainWindow w;    if (!createConnection())        return 1;    w.show();        return a.exec();}

 

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.