Home > other >  Qt database connection break line reconnection
Qt database connection break line reconnection

Time:10-11

As title, can you tell me the qt database connection how to implement the break line reconnection? Oneself done a test, connected to the database, use the finite of timer output connection, and open the connection, but after manual disconnect, void TQSqlDatabase: : timerEvent (QTimerEvent * event) {QSqlQuery query (conn); Query. The exec (" select top 1 sid from ShowInfoConfig "); Bool status=query. Next (); QDebug () & lt; & lt; Conn. IsValid () & lt; & lt; Conn. IsOpen () & lt; & lt; The status; } the output state of the two is still true, only when the query to know the status of the connection, this also too SB...

CodePudding user response:

If is MySql can try this,
QSqlDatabase dbConnLocal=QSqlDatabase: : addDatabase (" QMYSQL ", connNameLocal);
DbConnLocal. SetConnectOptions (" MYSQL_OPT_RECONNECT=1 ");
  • Related