[PyQt] PyQt book: problem with database example
mark at qtrac.eu
Thu Jan 10 15:51:53 GMT 2008
On 2008-01-10, Phil Thompson wrote:
> On Thursday 10 January 2008, Mark Summerfield wrote:
> > On 2008-01-09, Sibylle Koczian wrote:
> > > Hello,
> > > - After leaving the application I get the error message
> > > "QSqlDatabasePrivate::removeDatabase: connection
> > > 'qt_sql_default_connection' is still in use, all queries will cease to
> > > work." I have had this message in my own programs - it went away,
> > > when I didn't define a "main" funktion, but put its content directly
> > > under "if __name__ == '__main__':". But I never understood why this
> > > should be so.
> > The error message is harmless, but annoying. I don't think it is due to
> > any bug in the application, but rather a problem in PyQt regarding the
> > lifetime of the default connection, so I'm passing the buck to Phil on
> > this one.
> Yes it's to do with the (random) order that objects get garbage collected
> when the interpreter exits. You need to make sure that the objects that
> internally reference the default connection are deleted before the
> QApplication instance.
> In the case of assetmanager placing the following lines after the call to
> app.exec_() does the trick...
> del form
> del db
> Unfortunately I can't do anything about this as QSqlDatabase isn't a
> QObject, or even has a virtual dtor.
This works for the assetmanager.pyw application (and I'll put it in a
new zip & tarball when I make them in the next few days when I switch
the license to GPL 2). But if you change
in the phone log applications they still produce the error message...
Mark Summerfield, Qtrac Ltd., www.qtrac.eu
More information about the PyQt