When using QT for MySQL database operations in a Windows environment, the following issues occur:
Qsqldatabase:qmysql driver not loadedqsqldatabase:available drivers:qsqlite QODBC3 QODBC
This is due to the fact that the MySQL database driver is not compiled under QT (to be sure, it is not compiled with Mingw32 ), and the workaround is as follows:
1. Custom install MySQL, note the installation directory do not have spaces, my directory in
5.6
Although the secondary directory has spaces, it has no effect.
2. Open qt Command Prompt and switch to directory:
3. Execute the following command:
" includepath+=c:\mysql\mysql Server 5.6\include " " libs+=c:\mysql\mysql Server 5.6\lib\libmysql.lib " Mysql.pro
Note that the above directory is related to the installation of MySQL version, I use the version is:
Mysql-installer-community-5.6.26.0.msi
4. Implementation
Mingw32-make
The following error may appear here:
In file included fromMain.cpp: -:../.. /.. /sql/drivers/mysql/qsql_mysql.h: the: +: Error:mysql.h:no such file or directory in file included fromMain.cpp: -:../.. /.. /sql/drivers/mysql/qsql_mysql.h:108: error:expected')'Before'*'Tokenmingw32-make[1]: * * * [TMP/OBJ/DEBUG_SHARED/MAIN.O] Error1Mingw32-make[1]: Leaving directory ' c:/qt/2010.02.1/qt/src/plugins/sqldrivers/mysql'Mingw32-make: * * * [Debug-all] Error2
This is caused by not including the MySQL library file, add the following code in the Mysql.pro file:
" c:/mysql/mysql Server 5.6/include " "c:/mysql/mysql Server 5.6/lib/libmysql.lib"
Repeat step 4 to generate the following 4 files:
qsqlmysql4.dlllibqsqlmysql4.aqsqlmysqld4.dlllibqsqlmysqld4.a
5. Copy libmysql.lib from C:\MySQL\MySQL Server 5.6\lib\ to C:\Qt\2010.05\mingw\bin.
End of text
Reference:
1. http://blog.csdn.net/wang_xuehen/article/details/7483133
2. http://blog.csdn.net/wang19870102/article/details/39318225
3. http://www.cppblog.com/biao/archive/2011/10/29/159296.html
Windows under QT MySQL driver compilation