Qt4: Solution to the MySQL driver not loaded Problem

Source: Internet
Author: User

Qt4: Solution to the MySQL driver not loaded Problem

Write the QT application and use MySQL to access data. The following prompt is displayed when you connect to the database: (and the MySQL driver has been compiled)

Cause: the MySQL driver is not added to QT. The result is as follows.

The program can be downloaded by accessing my resources. google has not found any results for several days. finally, I decided to use the most stupid method to troubleshoot the problem one by one. Finally, I knew why I could not load the MySQL driver.

There are several causes for drive not loaded:
1. MySQL has not been installed when QT is installed. That is to say, the MySQL database should be installed before QT is installed. This error is thrown by qsqldatabase. DB. lasterror (). Text ()
2. Put the previously compiled MySQL driver into the QT folder by mistake.
3. Your program is wrong.
4. "driver not loaded" is an error thrown by query. lasterror (). Text.
Now that you know the reason, it's easy to solve it.
1. reinstall QT and the MySQL driver.
I have nothing to say about the solution of 2 and 3.
4. it indicates that your query was not associated with qsqldatabase during creation. the correct method is to declare qsqldatabase and then declare query. if you want a connection to be associated with multiple queries, use the following syntax: qsqlquery query (db). DB is the Instance name of qsqldatabase.
For MySQL driver compilation, please refer to my previous blog article

Run the test again after installing the driver. You can see that QT has added support for MySQL.

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.