[PyQt] Parent child relationship: child survives parent

2013-07-12 Thread Volker Pilipp
I've got a little bit confused about ownership of objects in SIP  As
far as I understand, if ParentObject owns ChildObject, the destruction
of ChildObject is left to c++ i.e. the c++ destructor of ParentObject
is expected to destruct ChildObject.  This behaviour may result in a
seg fault if the python programmer does not make sure that ChildObject
goes out of scope before ParentObject does. Indeed, there are many
scenarios where this may happen accidentally.

That's what I would like to have:  The ChildObject keeps a reference
on ParentObject that is released during destruction of ChildObject,
where the Python destructor of ChildObject must  not  call the c++
destructor of the wrapped c++ instance (this is done during
destruction of ParentObject).
I am wondering if this behavior is possible to achieve in SIP.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Parent child relationship: child survives parent

2013-07-12 Thread Phil Thompson
On Fri, 12 Jul 2013 09:30:46 +0200, Volker Pilipp
volker.pil...@dectris.com wrote:
 I've got a little bit confused about ownership of objects in SIP  As
 far as I understand, if ParentObject owns ChildObject, the destruction
 of ChildObject is left to c++ i.e. the c++ destructor of ParentObject
 is expected to destruct ChildObject.  This behaviour may result in a
 seg fault if the python programmer does not make sure that ChildObject
 goes out of scope before ParentObject does. Indeed, there are many
 scenarios where this may happen accidentally.

If you are talking about QObject then you shouldn't get a segfault - you
should get a Python exception.

 That's what I would like to have:  The ChildObject keeps a reference
 on ParentObject that is released during destruction of ChildObject,
 where the Python destructor of ChildObject must  not  call the c++
 destructor of the wrapped c++ instance (this is done during
 destruction of ParentObject).

The Python destructor will not call the C++ destructor if the C++ instance
has a parent. If you think it does then provide a test case that
demonstrates it.

 I am wondering if this behavior is possible to achieve in SIP.

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt