diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-09-07 15:49:37 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-09-12 12:17:23 +0000 |
commit | d99e0764e2fe9bc7e652474b5d70e8b66154b807 (patch) | |
tree | db159cfa9b6c4b4579104475420f12b04dcb98e1 /src/quicktemplates2/qquicklabel.cpp | |
parent | 04779d6db3e8219ebda62de4a6f8e57fa62c0b6a (diff) |
Delete replaced delegates after Component.completed() is emitted
This avoids the issue "Object destroyed during incubation" error.
A proper fix is still required in the QML engine.
Change-Id: I3c168cfe2d8c295662bcb5886e99a0f95748e302
Task-number: QTBUG-50992
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicklabel.cpp')
-rw-r--r-- | src/quicktemplates2/qquicklabel.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp index 6a0c6a0b..03bed16f 100644 --- a/src/quicktemplates2/qquicklabel.cpp +++ b/src/quicktemplates2/qquicklabel.cpp @@ -167,6 +167,18 @@ QAccessible::Role QQuickLabelPrivate::accessibleRole() const } #endif +/* + Deletes "delegate" if Component.completed() has been emitted, + otherwise stores it in pendingDeletions. +*/ +void QQuickLabelPrivate::deleteDelegate(QObject *delegate) +{ + if (componentComplete) + delete delegate; + else + pendingDeletions.append(delegate); +} + QFont QQuickLabel::font() const { return QQuickText::font(); @@ -205,7 +217,7 @@ void QQuickLabel::setBackground(QQuickItem *background) if (d->background == background) return; - delete d->background; + d->deleteDelegate(d->background); d->background = background; if (background) { background->setParentItem(this); @@ -230,6 +242,9 @@ void QQuickLabel::componentComplete() if (!d->accessibleAttached && QAccessible::isActive()) d->accessibilityActiveChanged(true); #endif + + qDeleteAll(d->pendingDeletions); + d->pendingDeletions.clear(); } void QQuickLabel::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) |