[Qt-interest] Removing a database connection

Mihail Naydenov mlists at ymail.com
Sun Dec 13 15:41:40 CET 2009





----- Original Message ----
> From: Jan <janusius at gmx.net>
> To: qt-interest <qt-interest at trolltech.com>
> Sent: Sun, December 13, 2009 3:57:07 PM
> Subject: Re: [Qt-interest] Removing a database connection
> 
> 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?
> > 

Humm, are you *sure* the second works? If the statements are equivalent it *should* report 
"QSqlDatabasePrivate::removeDatabase: connection 'default' is still in use ..."
Because QSqlDatabase::defaultConnection is just a static member string = "qt_sql_default_connection", nothing more.

MihailNaydenov

PS isn't removeDatabase static?



      



More information about the Qt-interest-old mailing list