Compile the MySQL driver of Qt in Linux

Source: Internet
Author: User
The QtSDK contains the QtCreator and Qt basic libraries and is a very good development environment. However, In the plugins of the Qt base library in the installation package, the database driver is only sqlite, not

The Qt SDK contains the QtCreator and Qt base libraries and is a very good development environment. However, In the plugins of the Qt base library in the installation package, the database driver is only sqlite, not

The Qt SDK contains QtCreator and Qt basic libraries and is a very good development environment. However, the database driver in the plugins of the Qt base library in this installation package is only sqlite and does not contain the MySQL driver. MySQL is a very common database platform.
If you need a MySQL driver, follow these steps:

To the next Qt source package of Trolltech, which contains the MySQL-driven source program. Before compiling the MySQL driver, make sure that you have installed the complete MySQL database, including mysql-devel, which is required by the compilation driver.

The following uses my machine environment as an example.
Tar-zxvf qt-x11-opensource-src-4.5.1.tar.gz
Cd qt-x11-opensource-src-4.5.1/src/plugins/sqldrivers/mysql
Qmake-qt4 "INCLUDEPATH + =/usr/include/mysql" "LIBS + =-L/usr/lib/mysql-lmysqlclient_r" mysql. pro
Make

After the execution is complete, a file libqsqlmysql. so will be added to the path of the operation, which is the mysql driver of qt. Copy it to the corresponding Qt location of the Qt SDK, in my machine it is in/home/pub/qtsdk-2009.02/qt/plugins/sqldrivers.

Note:
1. The Qt source package version must be the same as the Qt version in the Qt SDK. Otherwise, the newly compiled driver system does not recognize the version.
2. During compilation, include and libs must specify the path to the MySQL header and library.

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.