[PyQt] How to close QSqlDatabase connection?
Sibylle Koczian
Sibylle.Koczian at t-online.de
Wed Nov 14 15:13:43 GMT 2007
Am Montag, 12. November 2007 20:55:20 schrieb Hans-Peter Jansen:
> Am Montag, 12. November 2007 schrieb Sibylle Koczian:
> > So I looked around and saw that I had this:
> >
> > def main(args):
> > app = QtGui.QApplication(args)
> > if not visa_conn():
> > sys.exit(1)
> > visa_mf = VisaMF()
> > visa_mf.show()
> > sys.exit(app.exec_())
> >
> > if __name__ == '__main__':
> > main(sys.argv[1:])
> >
> > while "cachedtable.py" has no separate main function and calls the app
> > constructor with the full list sys.argv. Doing the same in my own example
> > seems to do the trick. But why?
>
> I will (hopefully) leave a more satisfying answer to the experts, but
> omitting sys.argv[0] doesn't make any sense to me anyway. Maybe the process
> name is used internally for creating the default connection name, and
> creates a None, NULL, whatever mismatch on close later in this case.
>
> You may want to experiment a bit with faked sys.argv args, e.g.: [], [''],
> ['xxx'], and let us know about the outcome. Using a different database
> backend would also be interesting.
>
I did, and the content of the argument list seems to be quite unimportant:
app = QtGui.QApplication(args) with an arbitrary list "args" works without
error message - as long as I don't use a separate "main" function. That seems
to be the important difference, not the arguments to the QApplication
constructor. Which leads again to the question: why? What's wrong with such a
function?
I will try to find out more: can I put part of the code into main(), but not
all of it? Can I use such a function, if I don't call it "main()"? And I will
certainly use another database backend (firebird), but at the moment I doubt
very much if that will make any difference. It's more interesting to try PyQt
applications not using a database with and without a separate "main()".
Very mystified,
Sibylle
--
Dr. Sibylle Koczian
Fasanenstraße 12
82293 Mittelstetten
More information about the PyQt
mailing list