diff options
author | Doris Verria <doris.verria@qt.io> | 2020-10-13 07:51:37 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-10-14 22:53:50 +0000 |
commit | fcbeebc5828228078c38329940fabb80f22e3909 (patch) | |
tree | 4628ff6473a85e5fde5c93f15bcd822dc272ca80 | |
parent | c46e2e087e29016aec143ef83c72743d76e1501b (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
Change-Id: I16275fc2765fd77badc1c5d265e8ba5cd250163a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit b84852670da604d32fe7cf222f0a82c28fd29c53)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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 a05d8177ba..37889fd66b 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -3323,8 +3323,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); } |