From 3941af88662cdf8bad478813233986e695fa4dcc Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 5 Apr 2017 19:07:05 +0200 Subject: Cancel incubation recursively It turns out that cancelling the incubation of eg. a combobox popup alone is not enough when its children might be incubating and would be left incorrectly guarded. Cancel recursively the whole object tree of a replaced/destroyed delegate to avoid that. Task-number: QTBUG-50992 Change-Id: Ia06931c4c7af3ed8bb56af6c29eb51081c4fccbb Reviewed-by: J-P Nurmi --- src/quicktemplates2/qquickcontrol.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index b673a424..eb66f313 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -866,12 +866,24 @@ QLocale QQuickControlPrivate::calcLocale(const QQuickItem *item) } /* - Cancels incubation to avoid "Object destroyed during incubation" (QTBUG-50992) + Cancels incubation recursively to avoid "Object destroyed during incubation" (QTBUG-50992) */ +static void cancelIncubation(QObject *object, QQmlContext *context) +{ + const auto children = object->children(); + for (QObject *child : children) + cancelIncubation(child, context); + QQmlIncubatorPrivate::cancel(object, context); +} + void QQuickControlPrivate::destroyDelegate(QObject *delegate, QObject *parent) { - if (delegate && parent) - QQmlIncubatorPrivate::cancel(delegate, qmlContext(parent)); + if (!delegate) + return; + + QQmlContext *context = parent ? qmlContext(parent) : nullptr; + if (context) + cancelIncubation(delegate, context); delete delegate; } -- cgit v1.2.3