[PySide] What can be returned from a slot?

Yann Lanthony yann.lanthony at gmail.com
Sun Jan 13 14:28:25 CET 2013


Yes, I would say that without the parenting, the created instance is never
referenced so it's deleted to soon and accessing it in QML causes the
segfault.
In the wiki example, the listmodel is instanciated "thingList =
 ThingListModel(things)" - increasing the refcount - and then set as a
property of the QDeclarativeContext, so there's no such problem.

Glad it worked !

Regards,
Yann


2013/1/13 Yosef Meller <yosefmel at post.tau.ac.il>

> **
>
> On Sunday 13 January 2013 12:06:45 Yann Lanthony wrote:
>
> > I've just tested to create a slot like yours (creating and returning an
>
> > instance of my custom model) in my minimal app and I have no segfault.
>
> > Maybe it's because you don't give your TargetListModel a parent. So you
>
> > create it and immediately return it but no one takes its ownership and
> it's
>
> > deleted to soon. This might explain the segfault.
>
>
>
> Setting a parent works!
>
>
>
> If I understand correctly, Python loses its last reference to it (which
> doesn't happen in the wiki example) but when setting a parent PySide
> increases the Python refcount so it doesn't get GCed until the parent
> object is GCed. Does that sound right?
>
>
>
> Thanks a lot,
>
> Yosef.
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130113/2ee1328c/attachment.html>


More information about the PySide mailing list