[PyQt] Re: SIP bug with object lifetime

Phil Thompson phil at riverbankcomputing.co.uk
Mon May 14 18:04:17 BST 2007


On Monday 14 May 2007 5:30 pm, Giovanni Bajo wrote:
> On 5/14/2007 1:14 PM, 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...
>
> You didn't answer this: is the annotation going to work also for the
> queryList() / findChildren() case?

It would work if it was applied - but I haven't applied it to PyQt4. I've 
applied it to those methods that are known to return an internally generated 
instance.

> >> 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.
>
> What about asking for its parent, then? And if the parent is not wrapped
> in Python, creating a wrapper for it and asking again for its parent
> (etc. etc.)?

That's getting too PyQt specific. It's possible to come up with a scheme that 
would work, but I don't think it's worth it.

Phil


More information about the PyQt mailing list