Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with ListView and QAbstractItemModel
Forum Updated to NodeBB v4.3 + New Features

Problem with ListView and QAbstractItemModel

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    albertoMirada
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      trollixx
      wrote on last edited by
      #2

      You should set highlightRangeMode: ListView.StrictlyEnforceRange for your ListView to use currentItem/currentIndex safely, if I understand your problem correctly.

      Oleg

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved