1, set the environment variables, you need to add the following environment variables:
2, open qt command Prompt, enter the first command: CD%qtdir%\src\plugins\sqldrivers\mysql press ENTER,then enter the second command: Qmake "Includepath+=c:\mysql\include","Libs+=c:\mysql\lib\opt\libmysql.lib" Mysql.prolast input: Mingw32-make to compile. Alternatively, add the include file path and lib file path for MQL in the. Pro file as shown. Follow the steps above to complete the link configuration. Below you can write the code of the linked database, as follows:
void Userdata::link () { qsqldatabase db=qsqldatabase:: Adddatabase ("Qmysql"); Db.setport (3306); Db.sethostname ("127.0.0.1"); Db.setdatabasename ("chat"); Db.setusername ("root"); Db.setpassword ("admin"); if (!db.open ()) { qdebug () << "Unable to open database"; } Else { qdebug () << "Database connection established"; } db.exec ("SET NAMES GBK");}
Under-Windows QT connection MySQL database