[PyKDE] Issue with QDialog and lifetime

Giovanni Bajo rasky at develer.com
Thu May 26 14:09:36 BST 2005


Toby Dickenson <tdickenson at geminidataloggers.com> wrote:

>> Notice that WDestructiveClose does not collect the Python object (of
>> course). So you can easily do something like:
>>
>> class MyDialog(QDialog2):
>>      # bla bla
>>
>>      def accept(self):
>>          self.value = self.lineedit.text()
>>
>> and then later access that string.
>
> But then you need to have a different method to access the text before and
> after the close. I would rather:
>
> dlg = WhateverDlg(parent)
>     dlg.lineedit.setText('foo')
> try:
> ok = dlg.exec_loop()
> if ok:
> print dlg.lineedit.text()
> finally:
> dlg.deleteLater()
>
> plus you avoid the need for that boring code in accept()

That's right, I would rather that, but alas there is no perfect solution.
The thing I like most about this is that there can't be a programming error.
Either you get an exception because you forgot to save things in accept(),
or it works, period. Having a large codebase, I prefer things that either
crash or work perfectly, without having to go hunting memory leaks
everywhere :)
-- 
Giovanni Bajo




More information about the PyQt mailing list