[PyQt] Re: SIP bug with object lifetime

Phil Thompson phil at riverbankcomputing.co.uk
Mon May 14 12:14:12 BST 2007


On Monday 14 May 2007 11:04 am, Giovanni Bajo wrote:
> On 5/14/2007 11:01 AM, Phil Thompson wrote:
> > If the new /Transfer/ function annotation were to be applied to
> > viewport() then a gc association would be established between viewport
> > and ql with the ql Python object having a reference to the viewport
> > Python object. This would prevent viewport (and also o) from being
> > garbage collected until ql was.
>
> What about queryList()/findChildren()? In my original code, the
> C++-allocated instance was accessed through a queryList() call. It's
> basically the same (getting a reference to a C++ instance never seen
> before by Python), but I guess the annotation won't be enough...
>
> I wonder: can't you just apply it automatically to all cases where you
> create a wrapper for an already existing C++ object that was never
> wrapped before? How can't that be wrong?

Because you would be making the (possibly incorrect) assumption that the new 
one was a child of self.

> >> (PS: what about a debugging function in sip which tells who owns who?
> >> sip.owner(foo) which returns a sip.voidptr() to the owner if it's C++,
> >> or None if it's owned by Python. It would make debugging of situations
> >> like this a little easier... using weakref/SIGNAL(destroyed) can bring
> >> other bugs into the table and makes things more confusing)
> >
> > Would you want to use the value? Or would something like sip.debug(foo)
> > that displayed lots of stuff to stdout be better?
>
> I was thinking it just for debugging purposes, so sip.debug(foo) should
> be fine.

Actually I think I'll call it dump().

Phil


More information about the PyQt mailing list