[PyKDE] Issue with QDialog and lifetime

Giovanni Bajo rasky at develer.com
Thu May 26 11:24:28 BST 2005


Toby Dickenson <tdickenson at devmail.geminidataloggers.co.uk> wrote:
> On Wednesday 25 May 2005 16:13, Giovanni Bajo wrote:
>
>> So, I don't see any easy way to take care of this automatically. One
>> has to remember to manually destroy the dialog calling deleteLater
>
> Yes. My PyQt idiom for running a dialog is:
>
>     dlg = WhateverDlg(parent)
>     try:
>         ok = dlg.exec_loop()
>         if ok:
>             # do things in here maybe
>     finally:
>         dlg.deleteLater()
>
> which isnt so bad.

I now see that exec_loop() returns the dialog exit code. I thought one had to
call result() to acquire that. This said, if you don't need to access the
dialog itself after it's been closed, it is sufficient to do:

dlg = WhateverDlg(parent)
dlg.setWFlags(Qt.WDestructiveClose)
ok = dlg.exec_loop()
if ok:
   # do things

which means that you can have:

class QDialog2(QDialog):
   def __init__(self, parent=0, name=0, modal=False, flags=0)
       QDialog.__init__(self, parent, name, modal, flags |
Qt.WDestructiveClose)

Giovanni Bajo




More information about the PyQt mailing list