Solve the Problem of QT driver in MySQL
This problem has plagued me for some time, because after QT is installed, there is no MySQL driver, and the written program will prompt "driver not loaded ". But fortunately, the source code of the MySQL QT driver can be found in the src directory. Later, I used the method mentioned on QT assistant, but the library file cannot be generated and there is always a link error. Later Google, on the qtcn saw their station long hair an article, only to know that is the default MySQL library file is MS format, so the use of make, LD program connection will fail. If you use Linux,
So we only need to talk about it as assistant, as xchinux also mentioned below.
He also gave the solution. Transcription:
The following references reference from: http://www.qtcn.org/bbs/read.php? Tid = 4210 & fpage = & toread = & page = 1
Author: xchinux
Quote: Compile MySQL driver in qt4 opensource for mingw
Mingw-utils package download: http://www.qtcn.org/download/mingw-utils-0.3.tar.gz
In the qt4 document, we will talk about how to compile the MySQL driver in windows.
Code: [copy to clipboard] You need to get the MySQL installation files. run Setup. EXE and choose "custom install ". install the "libs & include files" module. build the plugin as follows (here it is assumed that MySQL is installed in c: \ mysql ):
Cd % qtdir % \ SRC \ plugins \ sqldrivers \ mysql
Qmake-O makefile "includepath + = c: \ mysql \ include" "libs + = c: \ mysql \ Lib \ opt \ libmysql. lib" mysql. Pro
Nmake
If you are not using a Microsoft compiler, replace nmake with make in the line above.
This is a place that is easy to mix up. The above is the libmysql. lib and nmake are used for compilation. If msvc compiler is used, there is no problem above. But if mingw compiler is used, an error will occur, undefined reference ..... This is caused by the library used by mingw and the library in different formats used by msvc. MySQL only provides databases available for msvc. To compile the qsqlmysql library for qt4 for mingw, we must first compile the libmysql. A file required by mingw, which can be generated using the mingw tool.
Reimp command in the mingw-utils package (if this command is not available, you can download this file from the address given at the beginning of this post, and copy the content in the decompressed bin directory to the bin directory of mingw. There are spaces in the default installation path during MySQL installation. We must first copy its include and Lib directories to a path without spaces, such as c: \ mysql)
Code: [copy to clipboard] cd c: \ mysql \ Lib \ OPT
Reimp-D libmysql. Lib
Dlltool-K-D libmysql. Def-l libmysql.
In this way, our command behavior (pay attention to qmake and make ):
Code: [copy to clipboard] cd % qtdir % \ SRC \ plugins \ sqldrivers \ mysql
Qmake-O makefile "includepath + = c: \ mysql \ include" "libs + = c: \ mysql \ Lib \ opt \ libmysql. A" mysql. Pro
If this appears, it doesn't matter (Reserved backslash characters are not recommended), continue to execute mingw32-make
The libmysql. A and MySQL. DLL files are generated under the % qtdir % \ plugins \ mysql \ DEBUG directory.
One thing is, download the mingw-utils-0.3.tar.gz file, just copy the reimp tool in it to the bin in your mingw directory, so that you can generate the required driver according to the above steps. After make is complete, the library file is generated in the system directory of QT.
Then use the mingw32-make release to generate files under the release directory