ios - Why is QML deleting my C++ ListView model? -
using qt 5.5.1 on ios 9 i'm trying assign dynamically created qabstractlistmodel model property of listview:
window { listview { model: api.model() delegate: delegate } component { id: delegate text { text: "test" } } } api c++ object assigned qml context setcontextproperty. model method q_invokable returns qabstractlistmodel *. works, listview populated data.
the problem when start scrolling. after second full scroll (to bottom, top , down again) listview starts clear out. debugger telling me qabstractlistmodel being destroyed.
i don't want set cppownership on model. there way prevent listview destroying model?
qml seems kind of broken in regard, i've experienced arbitrary deletions of objects still in use in multiple scenarios. objects parents , referenced js engine being deleted no apparent reason while js garbage still takes hundreds of megabytes of memory instead of being freed. applies both objects returned c++ , objects created in qml. when object returned c++ function qml, ownership passed qml engine, makes object vulnerable such arbitrary deletions.
the solution force cpp ownership , manage object's lifetime manually - keep in mind destroy() won't work on such objects, have use c++ function qml delete it.
qmlengine.setobjectownership(obj, qqmlengine::cppownership); also, bacarozzo mentioned, exposing model property api might appropriate form. depends on whether function accessor existing object or creates object itself.
at rate, keep in mind qml object lifetime management @ point cannot , should not trusted.
Comments
Post a Comment