From 394315d902d9068a53439737906c00d48023d182 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 11 Feb 2012 01:10:07 +0100 Subject: [PATCH] Move the removal of the Quit event to QWindow. Change-Id: If524127ba9dab9ef065aaf4079294295eef8e49b Reviewed-by: Bradley T. Hughes --- src/gui/kernel/qwindow.cpp | 3 ++ src/widgets/kernel/qwidget.cpp | 3 -- .../kernel/qguiapplication/tst_qguiapplication.cpp | 40 ++++++++++++++++++++++ .../kernel/qapplication/tst_qapplication.cpp | 40 ++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 43b7e39..61ae2a2 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -178,6 +178,9 @@ void QWindow::setVisible(bool visible) create(); if (visible) { + // remove posted quit events when showing a new window + QCoreApplication::removePostedEvents(qApp, QEvent::Quit); + QShowEvent showEvent; QGuiApplication::sendEvent(this, &showEvent); } diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e3a8908..f5a1ea1 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7245,9 +7245,6 @@ void QWidget::setVisible(bool visible) setAttribute(Qt::WA_KeyboardFocusChange, false); if (isWindow() || parentWidget()->isVisible()) { - // remove posted quit events when showing a new window - QCoreApplication::removePostedEvents(qApp, QEvent::Quit); - d->show_helper(); qApp->d_func()->sendSyntheticEnterLeave(this); diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 2fd875b..8d0836e 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -53,6 +53,7 @@ private slots: void focusObject(); void allWindows(); void topLevelWindows(); + void abortQuitOnShow(); }; class DummyWindow : public QWindow @@ -152,5 +153,44 @@ void tst_QGuiApplication::topLevelWindows() QCOMPARE(app.topLevelWindows().count(), 0); } +class ShowCloseShowWindow : public QWindow +{ + Q_OBJECT +public: + ShowCloseShowWindow(bool showAgain, QWindow *parent = 0) + : QWindow(parent), showAgain(showAgain) + { + QTimer::singleShot(0, this, SLOT(doClose())); + QTimer::singleShot(500, this, SLOT(exitApp())); + } + +private slots: + void doClose() { + close(); + if (showAgain) + show(); + } + + void exitApp() { + qApp->exit(1); + } + +private: + bool showAgain; +}; + +void tst_QGuiApplication::abortQuitOnShow() +{ + int argc = 0; + QGuiApplication app(argc, 0); + QWindow *window1 = new ShowCloseShowWindow(false); + window1->show(); + QCOMPARE(app.exec(), 0); + + QWindow *window2 = new ShowCloseShowWindow(true); + window2->show(); + QCOMPARE(app.exec(), 1); +} + QTEST_APPLESS_MAIN(tst_QGuiApplication) #include "tst_qguiapplication.moc" diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 7017c61..c600956 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -149,6 +149,8 @@ private slots: void testQuitLock8(); void globalStaticObjectDestruction(); // run this last + + void abortQuitOnShow(); }; class EventSpy : public QObject @@ -2560,6 +2562,44 @@ void tst_QApplication::testQuitLock8() // No hang = pass } +class ShowCloseShowWidget : public QWidget +{ + Q_OBJECT +public: + ShowCloseShowWidget(bool showAgain, QWidget *parent = 0) + : QWidget(parent), showAgain(showAgain) + { + QTimer::singleShot(0, this, SLOT(doClose())); + QTimer::singleShot(500, this, SLOT(exitApp())); + } + +private slots: + void doClose() { + close(); + if (showAgain) + show(); + } + + void exitApp() { + qApp->exit(1); + } + +private: + bool showAgain; +}; + +void tst_QApplication::abortQuitOnShow() +{ + int argc = 0; + QApplication app(argc, 0); + QWidget *window1 = new ShowCloseShowWidget(false); + window1->show(); + QCOMPARE(app.exec(), 0); + + QWidget *window2 = new ShowCloseShowWidget(true); + window2->show(); + QCOMPARE(app.exec(), 1); +} /* This test is meant to ensure that certain objects (public & commonly used) -- 2.7.4