Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-10854

Fetch More Example: Off by one bug in FileListModel.cpp

    XMLWordPrintable

Details

    • bd786961b0d65bdd1adb31eca0a050a4b9a1f39a

    Description

      In filelistmodel.cpp line 96, the fetchMore function works out how many "itemsToFetch" and sets the newly inserted rows to have first index "fileCount" and last index "fileCount+itemsToFetch".
      If I understand QAbstractItemModel::beginInsertRows correctly, the last index will be "fileCount+itemsToFetch - 1"

      void FileListModel::fetchMore(const QModelIndex & /* index */)
      {
      int remainder = fileList.size() - fileCount;
      int itemsToFetch = qMin(100, remainder);

      beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch); /// ERROR HERE

      fileCount += itemsToFetch;

      endInsertRows();

      emit numberPopulated(itemsToFetch);
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            boddie David Boddie (Inactive)
            cfs_sh Simon Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes