QT Access MySQL Database

Source: Internet
Author: User

QT4 does not support MySQL database access by default and requires manual compilation of dynamic Link libraries Qsqlmysqld.dll and qsqlmysql.dll. QT5 supports MySQL database access by default and has generated the above 2 DLL files by default.

QT Access MySQL database, need to keep the two types consistent, if the type is inconsistent, there may be error "Qmysql Driver not Loaded": The following:

The driver Qmysql is already included, but it just can't be loaded.

I use 32-bit QT5, and then customize the installation of 32-bit MySQL, can successfully access the MySQL database. As follows:

The test code is as follows:

    QSqlDatabase dbSQL=QSqlDatabase::addDatabase("QMYSQL");    dbSQL.setHostName("localhost");// 主机    dbSQL.setPort(3306);//端口    dbSQL.setDatabaseName("imageprocess");//数据库名字    dbSQL.setUserName("***");//***表示用户名    dbSQL.setPassword("***");//***表示密码    if( dbSQL.open() )    {        qDebug()<<"Successfully!!";//如果连接成功,则输出    }

QT Access MySQL Database

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.