[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyKDE] Issue with QDialog and lifetime
From: James Emerton <ephelon () gmail ! com>
Date: 2005-06-23 18:45:57
Message-ID: c9424d940506231145222cd55d () mail ! gmail ! com
[Download RAW message or body]
On 6/23/05, Giovanni Bajo <rasky@develer.com> wrote:
> > Does anyone see a potential problem with exec_loop() transferring
> > ownership of the dialog instance back to Python?
>
> Well, which C++ API would you intend to call to achieve this? We still need the
> QDialog to keep its parent widget because it is the widget on which the dialog
> is modal.
Well, the parent-child relationship still exists. You would end up
with a bad reference if the modal dialog's parent were destroyed. I
can't think of any correct code that would do this. (And doing this
in C++ would cause a different set of nasty errors.)
The strategy is to tie the lifetime of the modal dialog to the Python
reference. The ~QObject() will still clean up the parent's child
object list. This should make the behavior equivalent to the
idiomatic C++ code.
You should be able to test this with sip.transfer( dlg, 0 ) just
before dlg.exec_loop(). Ultimately, a sipTransfer() should be added
to the %MethodCode for exec_loop().
Of course, none of this addresses the potential exeception from
MyDialog.__init__() To do that, you would need to handle that case
explicitly. (This is not unprecidented in C++. If a ctor throws the
dtor is not called and the object must be manually cleaned up.)
I suppose the other option is to contaminate the public API of
QDialog. There IS already an obsolete bool parameter, 'modal' to the
QDialog ctor that could be co-opted to mean 'don't transfer
ownership'.
James
_______________________________________________
PyKDE mailing list PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic