[PyQt] QML garbage collects the model

Nenad Ognjanovic bgr.gyk at gmail.com
Tue Jul 22 15:02:39 BST 2014


This is a follow up on the previous thread "QML, pyqtSlot and ownership".
The problem I'm having is that QML garbage collects the model which is
in use by ListView. ListView initially gets the model by calling
Python function (pyqtSlot) which instantiates and returns the model
(the function changes the ownership of the model before returning).
This works fine until the garbage collector gets triggered, at which
point QML will collect the model, and ListView will have missing items
after scrolling.

I have prepared the example that demonstrates this, which can easily
be tweaked to use different object ownership transfer methods and
model data types, as described in the source code.
The code is attached, and can also be checked out at this gist:
https://gist.github.com/bgr/1e43b12f088e07465afb
In its core the code could be 3x shorter, but I've expanded it to
cover a couple of different approaches. There is a simpler version of
the code at revision #1 of the gist.
I have also tried registering DummyModel and DummyObject with
qmlRegisterType after I've uploaded the example, it also has no
effect.

I have no clue whether it's a bug or if I'm doing something totally
wrong, but one important thing to note is that when
GUIEntryPoint.get_model is converted to be a pyqtProperty the problem
doesn't occur.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyqt_qml_gc_problem.py
Type: text/x-python
Size: 4576 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140722/e46f7cb7/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ui.qml
Type: text/x-qml
Size: 519 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140722/e46f7cb7/attachment.bin>


More information about the PyQt mailing list