void QSqlDatabase::removeDatabase(const QString &connectionName)
Removes the database connection connectionName from the list of database connections.
Warning: There should be no open queries on the database connection when this function is called, otherwise a resource leak will occur.
Example:
// WRONG
QSqlDatabase db = QSqlDatabase::database("sales");
QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES"

博客介绍了QSqlDatabase::removeDatabase函数,该函数用于从数据库连接列表中移除指定连接。调用时需确保数据库连接上无打开的查询,否则会导致资源泄漏。此函数是线程安全的,且removeDatabase与database配套,移除前要保证对象被销毁。
最低0.47元/天 解锁文章
1004





