[PyQt] segfault when using qml (probably reference counting error)
rdieter at math.unl.edu
Fri Mar 18 20:56:34 GMT 2011
On 03/18/2011 03:55 PM, Phil Thompson wrote:
> 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>
>>> Quoting downstream bug report,
>>> (Using PyQt-4.8.3)...
>>> When running some simple PyQt4 + QML apps, a segfault can be produced
>>> 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
>>> reference to the object removes the segfault. This likely means that a
>>> reference to the object is not being created in the PyQt4 declarative
>>> 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