QWidgetWindow: Immediately forward close events to QWindow
This way the platform window is destroyed in a timely manner, preventing redundant close events from the window system. Task-number: QTBUG-43344 Change-Id: Ifdfca59ceacef54405f1c227c493dc514a1b27ea Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
e69b6d2dbc
commit
e0b5ff4ad5
@ -237,6 +237,7 @@ bool QWidgetWindow::event(QEvent *event)
|
||||
switch (event->type()) {
|
||||
case QEvent::Close:
|
||||
handleCloseEvent(static_cast<QCloseEvent *>(event));
|
||||
QWindow::event(event);
|
||||
return true;
|
||||
|
||||
case QEvent::Enter:
|
||||
|
@ -401,6 +401,8 @@ private slots:
|
||||
|
||||
void tabletTracking();
|
||||
|
||||
void closeEvent();
|
||||
|
||||
private:
|
||||
bool ensureScreenSize(int width, int height);
|
||||
|
||||
@ -10798,5 +10800,31 @@ void tst_QWidget::tabletTracking()
|
||||
QTRY_COMPARE(widget.moveEventCount, 3);
|
||||
}
|
||||
|
||||
class CloseCountingWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
int closeCount = 0;
|
||||
void closeEvent(QCloseEvent *ev) override;
|
||||
};
|
||||
|
||||
void CloseCountingWidget::closeEvent(QCloseEvent *ev)
|
||||
{
|
||||
++closeCount;
|
||||
ev->accept();
|
||||
}
|
||||
|
||||
void tst_QWidget::closeEvent()
|
||||
{
|
||||
CloseCountingWidget widget;
|
||||
widget.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
||||
// Yes we call the close() function twice. This mimics the behavior of QTBUG-43344 where
|
||||
// QApplication first closes all windows and then QCocoaApplication flushes window system
|
||||
// events, triggering more close events.
|
||||
widget.windowHandle()->close();
|
||||
widget.windowHandle()->close();
|
||||
QCOMPARE(widget.closeCount, 1);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QWidget)
|
||||
#include "tst_qwidget.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user