QT通过query.exec(str)判断数据库是否断开连接

通过query.exec(str)执行sql语句判断数据库是否断开连接

 

QSqlDatabase db;

QSqlQuery query(db);

  // bool b_ret= query.exec(sql_comm);

//执行SQL查询:bool b_ret= query.exec("SELECT * FROM mytable where name='abc'");
    if(b_ret==true)

{

连接中。。。

}

else

{

已断开

}

 

posted @ 2025-06-26 15:46  txwtech  阅读(20)  评论(0)    收藏  举报