Problem with ListView and QAbstractItemModel
-
Hello. I have a QAbstractItemModel that asynchronously access to a DB and stores a cache of Object*s. It acts as a model for a ListView, in QML. The view is feeded with the objects stored in the cache (the "data" method takes the objects from that cache).
I do a beginInsertModel/endInsertModel for resetting the object cache. When the reset is ended, the view calls again the data method per each element, and rows are painted right, but the currentIndex property has the same value than before the beginResetModel (2) and the currentItem is null (this is the problem). If I try currentIndex = 2, the currentItem is not updated and remains null, because the value set is not different. It works if i do currentIndex = 1; currentIndex = 2.
Maybe am I missing something?
-
You should set highlightRangeMode: ListView.StrictlyEnforceRange for your ListView to use currentItem/currentIndex safely, if I understand your problem correctly.