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

QListView accesses incorrect index in QListModeViewBase::flowPositions

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.5.0
    • Widgets: Itemviews
    • None
    • OS: ANY
      COMPILER: ANY

    Description

      QListView tries to access QListModeViewBase::flowPositions at incorrect index position.
      This can be achieved when list view's layout mode is set up to Batched.
      Then call scrollTo() method with an index as an argument which row will be equal to size of QListModeViewBase::flowPositions - 1.

      There is a code to test the bug:

          QListView* view = new QListView();
          view->setLayoutMode(QListView::Batched);
          int batchSize = view->batchSize();
      
          //view->setBatchSize(batchSize);
      
          QStandardItemModel* model = new QStandardItemModel();
          for (int i = 0; i < batchSize + 10; ++i)
          {
              model->appendRow(new QStandardItem(QString::number(i)));
          }
      
          view->setModel(model);
          // this line will make assert:
          view->scrollTo(model->index(batchSize - 1, 0));
      

      The problem seems to be incapsulated in the method QListModeViewBase::indexToListViewItem
      In the condition at the top there is a check:

      index.row() >= flowPositions.count()

      But flowPositions is +1 larger than actual row count (see QListModeViewBase::perItemScrollToValue).

      Therefore the condition at QListModeViewBase::indexToListViewItem should be:

      index.row() >= flowPositions.count() - 1

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            ailin Aleksei Ilin
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes