Windows under QT connection MySQL database

Source: Internet
Author: User

1, set the environment variables, you need to add the following environment variables:

    2, open qt command Prompt, enter the first command: CD%qtdir%\src\plugins\sqldrivers\mysql press ENTER,then enter the second command: Qmake "Includepath+=c:\mysql\include","Libs+=c:\mysql\lib\opt\libmysql.lib" Mysql.prolast input: Mingw32-make to compile. Alternatively, add the include file path and lib file path for MQL in the. Pro file as shown. Follow the steps above to complete the link configuration. Below you can write the code of the linked database, as follows:
void Userdata::link () {    qsqldatabase db=qsqldatabase:: Adddatabase ("Qmysql");     Db.setport (3306);    Db.sethostname ("127.0.0.1");    Db.setdatabasename ("chat");    Db.setusername ("root");    Db.setpassword ("admin");    if (!db.open ()) {        qdebug () << "Unable to open database";    } Else {        qdebug () << "Database connection established";    }     db.exec ("SET NAMES GBK");}

Under-Windows QT connection MySQL database

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.