From e2b3d42f946a7702a92412f8c603f13ad53a4566 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 15 Oct 2020 11:46:17 +0200 Subject: Don't divide by zero when calculating number of items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amends e74af68654c0eb127277c73e20bda409b83d157b. If the model has children, then row 0 should have a non-zero size, but it's not unthinkable that a delegate returns zero for size hint, so protect against that case. Task-number: QTBUG-87588 Pick-to: 5.15 Change-Id: Ia396f532d42ce5fad8757d629816c3cdc31d84ed Reviewed-by: Jan Arve Sæther Reviewed-by: Doris Verria Reviewed-by: Florian Bruhin --- src/widgets/itemviews/qtreeview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index f3e0e06a56..502d64eaf6 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -3347,7 +3347,7 @@ void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninit model->fetchMore(parent); // 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; + const int viewCount = itemHeight ? viewport->height() / itemHeight : 0; int lastCount = -1; while ((count = model->rowCount(parent)) < viewCount && count != lastCount && model->canFetchMore(parent)) { -- cgit v1.2.3