From b84852670da604d32fe7cf222f0a82c28fd29c53 Mon Sep 17 00:00:00 2001 From: Doris Verria Date: Tue, 13 Oct 2020 07:51:37 +0200 Subject: [PATCH] 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 --- src/widgets/itemviews/qtreeview.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); }