Today I want to try how to connect to the database with QT. I am depressed when I have finished writing the prompt driver not loaded. My own environment of vs2010 + qt4.8.4 + mysql5.1 was found to be C: \ QT \ 4.8.4 \ plugins \ sqldrivers without MySQL DLL and Lib files. Therefore, you must compile it yourself.
1. Run QT 4.8.4 command prompt command to enter ($ qtdir $) \ SRC \ plugins \ sqldrivers \ mysql
2. Because the absolute path of MySQL has spaces, makefile cannot be accurately found.
Create a new MySQL folder (for example, c: \ mysql) in the root directory of any drive letter, and copy the ($ mysqldir $) \ inlcude and ($ mysqldir $) \ Lib folders to this folder.2. Enter the command
Qmake-O makefile "includepath + = c: \ mysql \ include""Libs + = c: \ mysql \ Lib \ opt \ libmysql. lib" mysql. Pro
Nmake3. Check whether the file is generated in the ($ qtdir $) \ plugins \ sqldrivers folder.
Sqlmysql4.dll, qsqlmysql4.lib, qsqlmysqld4.dll, qsqlmysqld4.lib
Qsqldatabase DB = qsqldatabase: adddatabase ("qmysql"); dB. sethostname ("localhost"); dB. setdatabasename ("mydb"); dB. setusername ("root"); dB. setpassword (""); If (! DB. open () qmessagebox: Information (this, TR (""), DB. lasterror (). Text ());
No ..