Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
5.9.5
-
None
Description
If you e.g. set a QList<QObject*> as the model of a ListView and reference data in the object from the delegate, and then delete one or more of the QObjects in the list without changing the model, you can get a crash.
To reproduce, run the attached example and click on "Create objects" and then on "Destroy objects". Notice that the list does not update. Try scrolling the list and you will see it crash as it tries to address one of the deleted objects.
I am not sure if this is intended to work, but I wanted to report it to hear the opinion of maintainers. It is inconsistent with how QML usually works, where you are usually prevented from shooting yourself in the foot. If you e.g. set a QObject directly as a property and then delete the object, the property will automatically become null and it will be handled gracefully. In a complex application, it is quite easy to get into the situation where you set the model of a list view and hide the list without unsetting the model, then delete some of the objects. In this case you may then get crashes later because QML still has the dangling pointers in its scope. The ideal situation would be if you ended up with a model full of nulls and got warnings from QML instead if you tried to access them.
If it is expected behavior, then feel free to close this task, but perhaps the documentation should warn against using QList<QObject*> as models in that case.