Qt5.8 Link Mysql Error and workaround

Source: Internet
Author: User
Tags mysql version

Qt 5.8 Under Link Mysql (under Windows platform), a friend will appear with this cannot connect error

Qsqldatabase:qmysql Driver not loaded

Qsqldatabase:available drivers:qsqlite qmysql QMYSQL3 qodbc QODBC3 qpsql QPSQL7

The solution is as follows

Depending on the Qt version, 32 and 64, the required drivers are different, in general, regardless of what version of MySQL, 64-bit QT to use 64-bit MySQL driver, 32-bit QT to use the 32-bit MySQL driver, seemingly with the installation of MySQL version did not What relationship Oh ~ ~ ~

We need to copy the/mysql/lib (own Mysql installation directory to find out where we are looking for ourselves) under the directory Libmysql.dll to the/Qt/mingw53_32/bin directory.

The test code is as follows:

    Qsqldatabase    Dbconn;
    Qsqlquery       query;
    Dbconn = Qsqldatabase::adddatabase ("Qmysql");
    Dbconn.sethostname ("localhost");//Host Name
    Dbconn.setdatabasename ("Since");//Database name
    Dbconn.open ("root", "123456");//username, password, successfully returned 1
    query = (qsqlquery) dbconn;
    Query.exec ("SELECT * from First");
    while (Query.next ())
    {
        int id = query.value (0). ToInt ();
        QString name = Query.value (1). ToString ();
        Qdebug () << qstring::number (ID) + ":" + name;
    }

The test results are:

Starting E:\since2017\Testmysql\release\Testmysql.exe ...

"0:since"

"1:never"

Before you do the MySQL operation, please make sure that the MySQL service is turned on Oh, the individual blog also strong point in the installation of MySQL to open the network connection, do not know if there is no need, may be remote connection when you need it ~ ~ ~

Thank the Bo Friend for my inspiration, such as the link to MySQL this still have questions can refer to this friend's blog OH

http://blog.csdn.net/cateatapple/article/details/52279168

Http://www.cnblogs.com/hbrw/p/6753849.html

Qt5.8 Link Mysql Error and workaround

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.