[Qt-interest] Removing a database connection

Jan janusius at gmx.net
Sun Dec 13 14:57:07 CET 2009


well, I noticed this is only partly a solution. Now I have to add 
QSqlDatabase::database("default") to *all* QSqlQuerys, models etc. pp
... :-(

Jan schrieb:
> 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?
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 



More information about the Qt-interest-old mailing list