[Qt-interest] Removing a database connection

Jan janusius at gmx.net
Sun Dec 13 15:50:24 CET 2009


Thx, you are right. It should be:

QSqlDatabase::removeDatabase(QSqlDatabase::defaultConnection);

to avoid the message.



Mihail Naydenov schrieb:
> 
> 
> 
> ----- 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