Qt World Summit: Submit your Presentation

incremental loading without total count information

  • i'm wondering whether it is possible to implement incremental data loading in views without knowing the total number of results in advance?

  • QAbstractbModel has fundamental fetchMore(), https://doc.qt.io/qt-5/qabstractitemmodel.html#fetchMore, and for example the QSql models implement this 256 rows at a time. So incremental loading is going on regardless of row count.

    You can leverage that in your views. "Paging" can fetch the next block of rows.

  • @JonB
    for fetchMore() to work, i need to implement canFetchMore() which means i need to know whether there's more data available or not?
    how will data() be called for model index, if rowCount() is not known?

  • @user4592357
    You only have to know if there is more data to fetch, not how many total there is. But in any case I assume you can have canFetchMore() return true while you don't know, and only in fetchMore() do you do the next fetch and discover whether there was any more.

    If a QModelIndex is for row not yet fetched, you can have data() fetch more to resolve the reference if necessary. You wouldn't have to know the final rowCount() up front.

Log in to reply