Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Batch data prefetch in QAbstractItemModel
Qt 6.12 LTS is out! See what's new in the release blog

Batch data prefetch in QAbstractItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 509 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.
  • H Offline
    H Offline
    Helios
    wrote on last edited by
    #1

    Hi.

    I'm implementing a QListView with a model that gets its data from the network. When a listing is shown, it gets the entire dataset that will be used for the display role, since this is cheap. However, the decoration role is more expensive, so I want to only fetch those items that will be needed. I could do this inside the data() override, but it would be more efficient if I could know when the view is about to make a bunch of data() calls, so I can fetch all the information in a single network call. I'm not seeing any way to do this. Am I missing something, or is there really no way?

    Thanks.

    VRoninV 1 Reply Last reply
    0
    • H Helios

      Hi.

      I'm implementing a QListView with a model that gets its data from the network. When a listing is shown, it gets the entire dataset that will be used for the display role, since this is cheap. However, the decoration role is more expensive, so I want to only fetch those items that will be needed. I could do this inside the data() override, but it would be more efficient if I could know when the view is about to make a bunch of data() calls, so I can fetch all the information in a single network call. I'm not seeing any way to do this. Am I missing something, or is there really no way?

      Thanks.

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @Helios said in Batch data prefetch in QAbstractItemModel:

      if I could know when the view is about to make a bunch of data() calls

      You can't but there is a way around it, albeit not pretty.
      When data or multiData requires the decoration add this request to a QQueue then have slot connected to a QTimer that will check whether there is stuff in the queue and process it all at once.

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      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
      • Unsolved