Fix QML integration of widgets

We need to mark the object as deleted before destroying
it's declarative data, otherwise all sorts of bad things
can happen.

This fixes the qwidgetsinqml autotest in qtdeclarative.

Change-Id: I05a645ebe1ca7a50c8927e3dbd9ebb5aaf369a71
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
(cherry picked from commit 3e91625b58)
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Lars Knoll 2017-11-14 15:52:34 +01:00 committed by Nathan Collins
parent b458cb312c
commit c579f49e2a

View File

@ -1677,6 +1677,7 @@ QWidget::~QWidget()
} }
} }
d->wasDeleted = true;
if (d->declarativeData) { if (d->declarativeData) {
if (static_cast<QAbstractDeclarativeDataImpl*>(d->declarativeData)->ownedByQml1) { if (static_cast<QAbstractDeclarativeDataImpl*>(d->declarativeData)->ownedByQml1) {
if (QAbstractDeclarativeData::destroyed_qml1) if (QAbstractDeclarativeData::destroyed_qml1)
@ -8476,7 +8477,7 @@ bool QWidgetPrivate::close_helper(CloseMode mode)
data.is_closing = 1; data.is_closing = 1;
QPointer<QWidget> that = q; QPointer<QWidget> that = q;
QPointer<QWidget> parentWidget = q->parentWidget(); QPointer<QWidget> parentWidget = (q->parentWidget() && !QObjectPrivate::get(q->parentWidget())->wasDeleted) ? q->parentWidget() : nullptr;
bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose); bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose);
if (mode != CloseNoEvent) { if (mode != CloseNoEvent) {