create();
if (visible) {
+ // remove posted quit events when showing a new window
+ QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
+
QShowEvent showEvent;
QGuiApplication::sendEvent(this, &showEvent);
}
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);
void focusObject();
void allWindows();
void topLevelWindows();
+ void abortQuitOnShow();
};
class DummyWindow : public QWindow
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"
void testQuitLock8();
void globalStaticObjectDestruction(); // run this last
+
+ void abortQuitOnShow();
};
class EventSpy : public QObject
// 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)