Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Asynchronously populating a QAbstractItemModel not working
Forum Updated to NodeBB v4.3 + New Features

Asynchronously populating a QAbstractItemModel not working

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

    I am implementing an QAbstractItemModel which fetches data asynchronously over a slow connection. From what I read the methods in QAbstractItemModel should return a response immediately, which can be overwritten later. So I built a simple QAbstractItemModel overriding only rowcount and data.

    My algorithm is:

    Upon rowCount() called return cached value or 0 if never fetched before
    Fetch rowCount from remote slow database
    Upon receipt of response issue beginInsertRows and endInsertRows
    That works, but the data method is never called. So my 3 items in the view are empty. Why is 'data' not called for each item?

    ...I originally posted this in the QML forum but per suggestion maybe it belongs here instead.

    JonBJ 1 Reply Last reply
    0
    • ocgltdO ocgltd

      I am implementing an QAbstractItemModel which fetches data asynchronously over a slow connection. From what I read the methods in QAbstractItemModel should return a response immediately, which can be overwritten later. So I built a simple QAbstractItemModel overriding only rowcount and data.

      My algorithm is:

      Upon rowCount() called return cached value or 0 if never fetched before
      Fetch rowCount from remote slow database
      Upon receipt of response issue beginInsertRows and endInsertRows
      That works, but the data method is never called. So my 3 items in the view are empty. Why is 'data' not called for each item?

      ...I originally posted this in the QML forum but per suggestion maybe it belongs here instead.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @ocgltd
      You may not get a good response with just this explanation and no code. For example

      simple QAbstractItemModel overriding only rowcount and data

      This does not appear to meet the minimum requirements of Model Subclassing Reference as per https://doc.qt.io/qt-5/model-view-programming.html#read-only-access.

      I also don't understand when you your rowCount() ceases to just return 0. But that may be a detail.

      Your "slow" model also might benefit from implementation of the "fetch more" interface.

      A lot of people would suggest you test your implementation via QAbstractItemModelTester Class before you proceed any further.

      1 Reply Last reply
      6

      • Login

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