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 fileCodePudding user response: