Fix infinite loop triggered when displaying model with QTreeView

For some models like the QFileSystemModel canFetchMore() returns true even though fetchMore() doesn't return anything if setRootPath is false. To prevent an infinite loop, add a check to make sure the model's rowCount was updated during the loop.

Fixes: QTBUG-87273
Pick-to: 5.15
Change-Id: I16275fc2765fd77badc1c5d265e8ba5cd250163a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Doris Verria 2020-10-13 07:51:37 +02:00
parent fa93f1aeb0
commit b84852670d

View File

@ -3348,8 +3348,12 @@ void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninit
// guestimate the number of items in the viewport, and fetch as many as might fit // guestimate the number of items in the viewport, and fetch as many as might fit
const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight; const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight;
const int viewCount = viewport->height() / itemHeight; const int viewCount = viewport->height() / itemHeight;
while ((count = model->rowCount(parent)) < viewCount && model->canFetchMore(parent)) int lastCount = -1;
while ((count = model->rowCount(parent)) < viewCount &&
count != lastCount && model->canFetchMore(parent)) {
model->fetchMore(parent); model->fetchMore(parent);
lastCount = count;
}
} else { } else {
count = model->rowCount(parent); count = model->rowCount(parent);
} }