Fix crash if receiver destroys itself in closeEvent
We allow QWidget::closeEvent to "delete this", and verify that this works
in the tst_QWidget::testDeletionInEventHandlers test function. Sadly,
that test didn't reliably catch the issue introduced in
28b14b966f, where the receiver is accessed
after the delivery of QEvent::Close.
Handle the QWindow event delivery explicitly so that we don't need to
access the receiver after the event has been delivered.
There's nothing we can do to make the test fail more reliably in CI.
A QWindow deleting itself in closeEvent will still crash; perhaps we don't
want to allow that anyway.
Change-Id: I2b5c2d11ded71c4f22ae9862cdc459e1f93b3374
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
parent
2ed267c820
commit
e7bb3a8bd3
|
|
@ -2746,7 +2746,12 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||
}
|
||||
|
||||
bool res = false;
|
||||
if (!receiver->isWidgetType()) {
|
||||
if (receiver->isWindowType()) {
|
||||
res = d->notify_helper(receiver, e);
|
||||
// We don't call QGuiApplication::notify here, so we need to duplicate the logic
|
||||
if (res && e->type() == QEvent::Close)
|
||||
d->maybeQuitOnLastWindowClosed(static_cast<QWindow *>(receiver));
|
||||
} else if (!receiver->isWidgetType()) {
|
||||
res = d->notify_helper(receiver, e);
|
||||
} else switch (e->type()) {
|
||||
case QEvent::ShortcutOverride:
|
||||
|
|
@ -3342,10 +3347,6 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||
break;
|
||||
}
|
||||
|
||||
// We don't call QGuiApplication::notify here, so we need to duplicate the logic
|
||||
if (e->type() == QEvent::Close && receiver->isWindowType() && res)
|
||||
d->maybeQuitOnLastWindowClosed(static_cast<QWindow *>(receiver));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue