我写了一个析构函数,函数中调用了一个removeConnection()函数,原型如下:
bool removeConnection(QString &dbConnection)
{
QSqlDatabase db = QSqlDatabase::database(dbConnection);
if (db.isValid()) {
return false;
}
db.close();
QSqlDatabase::removeDatabase(dbConnection);
return true;
}
我测得析构函数中removeConnection()的返回值是false,所以我断定这值前连接数据库的QSqlDatabase对象已经被自动销毁了,即无需用析构函数来销毁数据库的连接对象。
不知道大家意见如何?