Ext.: http://blog.csdn.net/m15814478834/article/details/49902077
The recent use of QT encountered the "Qmysql driver not loaded" problem. There are a variety of answers on the web. Most of them can't solve the problem at all. There is no principle to solve the problem, the process is also cumbersome and extremely easy to make mistakes. People who want to see my article don't spend two weeks tossing versions of MySQL , each version of QT.
No time to see the final summary.
The process of QT connection to MySQL
QT->QT database Plug-in->mysql dynamic library->mysql
QT Database Plug-in is \plugins\sqldrivers under the qsqlmysqld.dll qsqlmysql.dll
MySQL Dynamic library is the libmysql.dll in the MySQL installation directory
The above DLL exists to successfully connect to the database. So the answer to the copy Libmysql.dll file represented by this article is more than half. In fact, the solution to the problem is purely fortunate. Of course, because of the need for DLLs, the configuration environment variables represented by this article mislead a lot of people, The way to configure environment variables is to look at the face. What MySQL space is more nonsense. At least qt5.1 started. There are no path spaces and no restrictions on Chinese.
So why a lot of people use Qt5 above version, which contains Qsqlmysqld.dll qsqlmysql.dll files, also put Libmysql.dll Copy to Qt bin or program output directory or driver not loaded?
Because different versions of MySQL contain different libmysql.dll, different libmysql.dll must work with the matching Qsqlmysqld.dll qsqlmysql.dll.
Know why, how to solve it? Find Libmysql.dll to recompile the corresponding version of Qsqlmysqld.dll Qsqlmysql.dll. Don't worry, just like me. I introduce a way to use QT Creater the method of compiling.
1: Open the Qt installation path under the source code. For example, C:\Qt\Qt5.2.0\5.2.0\Src\qtbase\src\plugins\sqldrivers\mysql. (If there is no SRC path, reinstall QT, choose a full installation) double-click Mysql.pro
2: If it is connected to the remote database, the machine can not install MySQL, but must find a MySQL installation directory to replicate to the local. Here the bread contains the Includ directory and the Lib directory.
3: Compile the Mysql.pro, prompt for a few header files, Mysql.pro Add the Include directory in the 2, and then compile, missing Lib file. Add lib file. Example
4: Copy the compiled qsqlmysqld.dll qsqlmysql.dll to \plugins\sqldrivers
5:mysql folder under the Lib path Libmysql.dll copied to the directory mingw47_32\bin
Summary: Different versions of MySQL contain different libmysql.dll, different libmysql.dll must be with the supporting Qsqlmysqld.dll Qsqlmysql.dll together to work properly . You can download others compiled well.
qsqlmysqld.dll qsqlmysql.dll Copy to \plugins\sqldrivers,libmysql.dll Copy to directory mingw47 _32\bin. Must be used in a matching, supporting use , supporting the use.
The principle and solution of Qmysql driver not loaded