How to connect to mysql in qt5.8
How to connect to mysql with qt5.8: first compile and generate the mysql driver; then download the “libmysql.dll” library and put it in the Qt bin folder; finally create a connection code file for testing Can. Recommendation: “Mysql Video Tutorial” qt5.8 connects to mysql database Qt Creator. Take qt5.8.0 and mysql5.7.18 as examples below. Preparation 1.qt5.2 and above, there is a mysql driver by default, we can in (eg: D:\Qt\Qt5.8.0\5.8\mingw53_32\ plugins\sqldrivers) to find the mysql driver. If there is no driver, then you have to compile and generate it yourself. 2. Download mysql (qt cannot find the library file of mysql) The file name of the library is “libmysql.dll”, and this library file should be placed in the bin folder of Qt (for example: D:\ Qt\Qt5.8.0\5.8\mingw53_32\bin) This file is usually in the lib directory of mysql. Test code #include “mainwindow.h” #include #include #include #include #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w. show(); QStringList drivers = QSqlDatabase::drivers(); qDebug() <<drivers; QSqlDatabase dbconn; QSqlQuery query; dbcOnn= QSqlDatabase::addDatabase("QMYSQL"); dbconn.setHostName("192.168.80.221");//host name dbconn.setDatabaseName("iacrms");//database name dbconn.open("gdzt", "039.com");//username, password, return 1 if successful query = (QSqlQuery)dbconn; query.exec("select * from tb_UserQQInfo"); while(query. next()) { int id = query. value(0). toInt(); QString name…