[Qt-interest] Removing a database connection
Jan
janusius at gmx.net
Sun Dec 13 14:38:27 CET 2009
Hi,
I know the error message "QSqlDatabasePrivate::removeDatabase:
connection 'qt_sql_default_connection' is still in use, all queries will
cease to work." has been discussed over and over.
But I still have a question: :-) I am struggling with closing a
connection and renaming the sqlite file afterwards. Renaming the file is
not possible if I get this error message. I think I found a solution
(but I don't really understand why it works).
This produces the error message above:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(qApp->applicationDirPath()+"/db.sqlite3");
db.close();
db = QSqlDatabase();
QSqlDatabase::database().removeDatabase(QSqlDatabase::defaultConnection);
... this not:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "default");
db.setDatabaseName(qApp->applicationDirPath()+"/db.sqlite3");
db.close();
db = QSqlDatabase();
QSqlDatabase::database().removeDatabase("default");
Why?
More information about the Qt-interest-old
mailing list