[PyQt] segfault when using qml (probably reference counting error)

Phil Thompson phil at riverbankcomputing.com
Fri Mar 18 20:55:53 GMT 2011

On Fri, 18 Mar 2011 16:20:23 +0000, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Fri, 18 Mar 2011 10:54:16 -0500, Rex Dieter <rdieter at math.unl.edu>
> wrote:
>> Quoting downstream bug report,
>> https://bugzilla.redhat.com/show_bug.cgi?id=676042
>> (Using PyQt-4.8.3)...
>> When running some simple PyQt4 + QML apps, a segfault can be produced
> when 
>> the QML tries to make use of an object that is exposed to it by the
>> code. Changing the code very slightly so that the PyQt4 code has an
> extra 
>> reference to the object removes the segfault.  This likely means that a

>> reference to the object is not being created in the PyQt4 declarative
> code.
>> the downstream bug also includes some sample code as a test-case.
> It's a feature, not a bug...
> PyQt correctly gives an extra reference to the Stopwatch context object
> the QDeclarativeContext returned by rootContext() to prevent it being
> garbage collected. However the QDeclarativeContext Python object (not
> C++ instance) is itself garbage collected and so the extra reference is
> then discarded.
> Therefore you need to keep an explicit reference to the Stopwatch
> (as in your workaround), or the value returned by rootContext(), or give
> the Stopwatch instance a sensible parent.

...on second thoughts I can make this work. Should be fixed in tonight's
SIP and PyQt snapshots.


More information about the PyQt mailing list