Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, January 2008
QSqlDatabase initialization issues


Message 1 in thread

I have the following warning when starting my application:
    "QSqlDatabasePrivate::removeDatabase: connection 'Output' is still in
use, all queries will cease to work."

I have a class with one QSqlDatabase member and one init function for
initializing the db

class DBOutput
{
public:
   QSqlDatabase db;
   void init();
}


void DBOutput::init
{
   db = QSqlDatabase::addDatabase("QMYSQL", "output");
}


The warning is triggered by the return of the DBOutput::init() function. The
compiler is probably destructing a QSqlDatabase instance, causing that
message. But I cannot figure why, and if it's still safe to use the database
member.


Thanks,

Etienne

Message 2 in thread

Hi,

On Monday 28 January 2008 19:12:21 Etienne Sandrà wrote:
> I have the following warning when starting my application:
>     "QSqlDatabasePrivate::removeDatabase: connection 'Output' is still in
> use, all queries will cease to work."
>
> I have a class with one QSqlDatabase member and one init function for
> initializing the db
>
> class DBOutput
> {
> public:
>    QSqlDatabase db;
>    void init();
> }
>
>
> void DBOutput::init
> {
>    db = QSqlDatabase::addDatabase("QMYSQL", "output");
> }
>
>
> The warning is triggered by the return of the DBOutput::init() function.
> The compiler is probably destructing a QSqlDatabase instance, causing that
> message. But I cannot figure why, and if it's still safe to use the
> database member.

it might be that you call the function twice, meaning you overwrite the first 
connection called "output" on the second call.

Note that the destructor of QSqlDatabase does not close the connection - you 
have to manually add/remove connections using the static members of 
QSqlDatabase.

Hope this helps,
Harald

--
 [ signature omitted ] 

Message 3 in thread

As a check, it is wise to add the following line before the addDatabase 
method:

if (! db.contains("output"))
	db = db = QSqlDatabase::addDatabase("QMYSQL", "output");

Thus if your init function is called more than once, the warning will 
not be triggered.

Karl

Harald Fernengel wrote:
> Hi,
> 
> On Monday 28 January 2008 19:12:21 Etienne Sandrà wrote:
>> I have the following warning when starting my application:
>>     "QSqlDatabasePrivate::removeDatabase: connection 'Output' is still in
>> use, all queries will cease to work."
>>
>> I have a class with one QSqlDatabase member and one init function for
>> initializing the db
>>
>> class DBOutput
>> {
>> public:
>>    QSqlDatabase db;
>>    void init();
>> }
>>
>>
>> void DBOutput::init
>> {
>>    db = QSqlDatabase::addDatabase("QMYSQL", "output");
>> }
>>
>>
>> The warning is triggered by the return of the DBOutput::init() function.
>> The compiler is probably destructing a QSqlDatabase instance, causing that
>> message. But I cannot figure why, and if it's still safe to use the
>> database member.
> 
> it might be that you call the function twice, meaning you overwrite the first 
> connection called "output" on the second call.
> 
> Note that the destructor of QSqlDatabase does not close the connection - you 
> have to manually add/remove connections using the static members of 
> QSqlDatabase.
> 
> Hope this helps,
> Harald
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 

-- 
 [ signature omitted ] 

Message 4 in thread

Etienne Sandrà wrote:
> I have the following warning when starting my application:
>     "QSqlDatabasePrivate::removeDatabase: connection 'Output' is still in
> use, all queries will cease to work."
> 

I ran into the same problem some time ago and if you look
back a couple of months in the archives for this list,
you'll find a long discussion of the problem, and a solution,
in the thread entitled:

"Unable to remove database ?"

which was started by me on 5/12/2007.

-- 
 [ signature omitted ]