[Interest] QObjectListModel approach with Qt5 and QML crashes sometimes

Railway Coder railwaycoder at gmail.com
Tue Feb 3 06:55:44 CET 2015


Hi,

I'm currently writing an application using Qt5 (C++ and QML).
It will get a big data backend in C++ which will get updated by different
hardware in realtime.

To get this data displayed in QtQuick. I found the QObjectListModel
approach which was presented on QtDD12:
http://qt-project.org/videos/watch/qml-for-desktop-apps

I've updated the QObjectListModel implementation to work with Qt5.

The application I've written sometimes crashes. It seems that this has to
to with the QObjectListModel approach.

I've put together a simple example to show this issue.
A simple git import from QtCreator should make it very simple for you to
test my
example application.

Clone URL:
https://railwaycoder@bitbucket.org/railwaycoder/qobjectlistmodelqmltesting.git

QObjectListModel is created in C++ and filled with 200 TestOBjects.
The OBjectListModel is than exposed to QML using
rootContext->setContextProperty(...)
In Qml there is a simple ListView filled with data from the
QObjectListModel childs.
At this point there are no problems.

But I want to do some actions with the TestObject selected in the ListView.
Therefore I added the following code:

onCurrentIndexChanged: {
            console.log(currentIndex)
            console.log(ObjectListModel.get(currentIndex))
        }

First testing looks also okay. But if you do fast scrolling up and down
using
keyboard or sometimes by simply selecting an item by mouse, the application
crashes with following error:

qml: TestObject(0x12e1820)
qml: 51
qml: TestObject(0x12e1610)
qrc:/main.qml:35: TypeError: Cannot reat property 'name' of null
qml: 50
The program has unexpectedly finished.

My idea about this issue is, that this has something to do with the
seperate QtQuick rendering thread in Qt5.
ListView sometimes needs to update it's data from the model and it seems if
in the same moment ObjectListModel.get(currentIndex) is called this issue
happens.

Maybe I am completly wrong and there is a simple mistake in my code?
Otherwise is this a bug? Or is it my task to take care of the QML rendering
thread?
Is QOBjectListModel approach best practise for accessing big data which is
asynchronylsy updated by C++?

Best Regards,
railwaycoder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150203/b1198b63/attachment.html>


More information about the Interest mailing list