Home > Mobile >  QT opened the MySQL database, takes about 5 seconds
QT opened the MySQL database, takes about 5 seconds

Time:09-18

Procedure is as follows:
Bool ado: : connectDB (QString strHostName, QString strDataBase, int nPort, QString strUserName, QString strPassword)
{
The dataBase=QSqlDatabase: : addDatabase (" QMYSQL ", "mynewcon");//use the connection name, if multiple times,
DataBase. SetHostName (strHostName);
DataBase. SetDatabaseName (strDataBase);
DataBase. SetPort (nPort);
DataBase. SetUserName (strUserName);
The dataBase. The setPassword (strPassword);
Bool bRet=false;
QDebug () & lt; <" The open before: "& lt;

BRet=dataBase. The open ();
QDebug () & lt; <" The open after: "& lt;
If (bRet==false)
{
QDebug () & lt; <" The database connect error: "& lt; }
Return bRet.
}
In the output debugging:

The open before: "the 2020-04-03 19:30:20:969"
The open after: "the 2020-04-03 19:30:26:612"
Will probably have close to 6 seconds, takes too long, have a solution?

CodePudding user response:

This should not code problem, is your mysql database is not local? If the connection is not a local database mysql under suggest modify the configuration of the reference https://blog.csdn.net/sinat_22550485/article/details/72385444's remote access speed slow change my. CNF file

CodePudding user response:

reference 1st floor juelianhuayao response:
this should not code problem, is your mysql database is not local? If the connection is not a local database mysql under suggest modify the configuration of the remote access to reference https://blog.csdn.net/sinat_22550485/article/details/72385444 slow change. My CNF file


Open the local database, I open the database in the ado class, B class invokes the connectdb function, good care of mulberry wow
  •  Tags:  
  • Qt
  • Related