Connect to Mysql in Qt5.4, QSqlDatabase: QMYSQL driver not loaded but available, qsqldatabaseqmysql
First from the help of this foreign god http://seppemagiels.com/blog/create-mysql-driver-qt5-windows, at the same time I hope that my blog can help some friends to solve this problem, I am also tangled for a long time, get bored, very understandable .... The tutorials on the Internet are all very old versions. If there is no correct tutorial, Google is better. I found it abroad. Fortunately, the English of this blog is not very complicated .... I am mainly writing Windows in this article. It is easy in Linux, and it is similar to the other. There are many online tutorials.
Qt5.4 comes with the Mysql driver,
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: qsqlite qmysql QMYSQL3 QODBC and so on, it indicates that Qt is built-in. But why does not load occur again? It is because the dependency of the driver is not satisfied, so it is necessary to re-compile
Tool: Qt5.4 (mingw4921332) and source code, Mysql5.5.30-win32.mis
Qt5.4 (mingw49000032) offline installation package, Qt5.4 (mingw49000032) source code
Mysql5.5.30-win32.mis (Baidu online storage)
We do not recommend that you use MySQL 5.5 or a later version. Currently, MySQL 5.6 or a later version is only 5.6. because MySQL and later versions cannot customize the installation location of MySQL, the installation location must be blank. although 5.6 can be used to customize folders, there are spaces in the folders, and 5.5 can be used to completely customize folders.
1. Install Mysql and Qt
You do not need to install it successively. you can install it first. For Mysql installation method, select Custom, that is, Custom, and then select the folder. I suggest C: \ MySQL \ MySQLServer5.5 \,, there must be a space, because the space below the command line indicates that the command is over, and then the next command will continue,
Qt no requirement, continue to Next on the line, my QT path is C: \ Qt, By the way to extract the source code, my pressure path is C: \ qt-everywhere-opensource-src-5.4.0
2. Re-compile the Mysql driver and add environment variables. There is no need to open the command line terminal of Qt. Click the Start Menu, Q5.4.0t. See
Enter cd C: \ qt-everywhere-opensource-src-5.4.0 \ qtbase \ src \ plugins \ sqldrivers \ mysql \ into this folder qmake "Export depath + = C: \ MySQL \ MySQLServer5.5 \ include "" LIBS + = C: \ MySQL \ MySQLServer5.5 \ lib \ libmysql. lib "-o Makefile mysql. promingw32-makeOK, compiled, if you have a series of errors, such as not found # include <mysql. h> wait. This is the path after your qmake contains spaces. Check it. 3. reconfigure the MySQL driver
Set qsqlmysql under the C: \ qt-everywhere-opensource-src-5.4.0 \ qtbase \ plugins \ sqldrivers folder. dll and qsqlmysqld. dll to C: \ Qt \ Qt5.4.0 \ 5.4 \ mingw491_32 \ plugins \ sqldrivers. A lot of tutorials are finished at this step. In fact, this is still not feasible, but it is still a step worse.4. The most critical last step is to copy C: \ MySQL \ MySQLServer5.5 \ lib \ libmysql. dll to C: \ Windows. All success! Start your Qt journey.
In Linux, the same is true. qmake *****, make, and copy the past, but there is no space in step 2, otherwise, various header files or files may not be found. If it is helpful to you, please comment on it. Thank you. I will be excited. Note: reposted, please explain the source. Thank you.