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.