QT even mysql database , The databases installed by everyone are generally 8.0 Version of ,64 Bit , Use it directly here QMYSQL connect , Missing driver found , And we use Qt
creater yes 32 position , So here we choose another way to link the database QODBC( Open database connection ), If you use 64 of mingw, Or msvc_2013,64 Bit , Then you can not use this method , Just connect directly

first , Find this in your own database 2 Files

Put it in the directory

  Click the control panel to find this icon

  Then click ODBC Data Sources (32-bit)

to configure

click Test If the next window appears, the connection is successful

                ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        

Let's check the code
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("test"); if(!db.open()){ qDebug()<<" Open failed "; }else{
qDebug()<<" Open successfully "; } QSqlQuery query(db); // Associated database query.exec("select * from
teacher"); // For executing statements while(query.next()) {
qDebug()<<query.value(0).toString()<<" " <<query.value(1).toString()<<" "
<<query.value(2).toString(); }
The effect is as follows

If it is msvc 64 position , Or migw64 of

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1"); db.setPort(3306);// yes mysql Port number of the server
db.setDatabaseName("test"); db.setUserName("root"); db.setPassword("123456");
if (!db.open()) { qDebug() << QString::fromLocal8Bit(" Open failed "); return 0; } else{
qDebug() << QString::fromLocal8Bit(" Open successfully "); } QSqlQuery query(db); // Associated database
query.exec("select * from ....;"); // Using query statements while (query.next()) { /* Output query results
*/ }
Summary :

         The local signal inside and after 127.0.0.1 After that, we will continue to explain the reasons in the chapter of network programming , With the help of database, we can better deal with many problems .

Technology