QSqlDatabasePrivate::removeDatabase: connection ‘in_mem_db’ is still in use, all queries will cease towork.
按照Qt官方教程的说法,内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Warning: There should be noopen 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", db); QSqlDatabase::removeDatabase("sales"); // will output a warning // "db" is now a dangling invalid database connection, // "query" contains an invalid result set The correct way to do it: { QSqlDatabase db = QSqlDatabase::database("sales"); QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db); } // Both "db" and "query" are destroyed because they are out of scope QSqlDatabase::removeDatabase("sales"); // correct