diff options
author | Doris Verria <doris.verria@qt.io> | 2020-10-13 07:51:37 +0200 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2020-10-14 21:43:45 +0200 |
commit | b84852670da604d32fe7cf222f0a82c28fd29c53 (patch) | |
tree | 232da66473ddd3b73f8d0061bdadbadc2ca94f4d | |
parent | fa93f1aeb0dd92acf0cbe2113425a1b21b8c82cb (diff) |
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>
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 3fd0da37cf..f3e0e06a56 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -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 const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight; 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); + lastCount = count; + } } else { count = model->rowCount(parent); } |