From e7df2279bf5519703fd0b853abaa23947a599920 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 23 Apr 2021 12:16:26 +0200 Subject: ScrollView: fix crash when scrolling with zero-sized item Check if a Flickable type was actually set as the contentItem before accessing the pointer. Also warn that using a type other than Flickable is not supported. Fixes: QTBUG-93039 Pick-to: 6.1 6.0 5.15 Change-Id: I1470766c6de02b7b601edf1375791d3147f26ab5 Reviewed-by: Volker Hilsheimer --- src/quicktemplates2/qquickscrollbar.cpp | 6 ++++++ src/quicktemplates2/qquickscrollview.cpp | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/quicktemplates2') diff --git a/src/quicktemplates2/qquickscrollbar.cpp b/src/quicktemplates2/qquickscrollbar.cpp index cc338b65..843b7d86 100644 --- a/src/quicktemplates2/qquickscrollbar.cpp +++ b/src/quicktemplates2/qquickscrollbar.cpp @@ -1014,6 +1014,9 @@ class QQuickFriendlyFlickable : public QQuickFlickable void QQuickScrollBarAttachedPrivate::scrollHorizontal() { + if (!flickable) + return; + QQuickFriendlyFlickable *f = reinterpret_cast(flickable); const qreal viewwidth = f->width(); @@ -1026,6 +1029,9 @@ void QQuickScrollBarAttachedPrivate::scrollHorizontal() void QQuickScrollBarAttachedPrivate::scrollVertical() { + if (!flickable) + return; + QQuickFriendlyFlickable *f = reinterpret_cast(flickable); const qreal viewheight = f->height(); diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp index 174495f6..1f5adbb7 100644 --- a/src/quicktemplates2/qquickscrollview.cpp +++ b/src/quicktemplates2/qquickscrollview.cpp @@ -585,7 +585,10 @@ void QQuickScrollView::contentItemChange(QQuickItem *newItem, QQuickItem *oldIte // assume/require that it has an explicit content size assigned. d->flickableHasExplicitContentWidth = true; d->flickableHasExplicitContentHeight = true; - d->setFlickable(qobject_cast(newItem), false); + auto newItemAsFlickable = qobject_cast(newItem); + if (newItem && !newItemAsFlickable) + qmlWarning(this) << "ScrollView only supports Flickable types as its contentItem"; + d->setFlickable(newItemAsFlickable, false); } QQuickPane::contentItemChange(newItem, oldItem); } -- cgit v1.2.3