Commit f75d55f1a71cae9864ca4bf12c92fcd9e34ed651
- Diff rendering mode:
- inline
- side by side
src/gui/kernel/qwidget.cpp
(9 / 11)
|   | |||
| 7573 | 7573 | if (isMain) | |
| 7574 | 7574 | QApplication::quit(); | |
| 7575 | 7575 | #endif | |
| 7576 | // Attempt to close the application only if this widget has the | ||
| 7577 | // WA_QuitOnClose flag set set and has a non-visible parent | ||
| 7578 | quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible() || parentWidget->testAttribute(Qt::WA_DontShowOnScreen)); | ||
| 7576 | // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent | ||
| 7577 | quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible()); | ||
| 7579 | 7578 | ||
| 7580 | 7579 | if (quitOnClose) { | |
| 7581 | // If there is no non-withdrawn primary window left (except | ||
| 7582 | // the ones without QuitOnClose or with WA_DontShowOnScreen), | ||
| 7583 | // we emit the lastWindowClosed signal | ||
| 7580 | /* if there is no non-withdrawn primary window left (except | ||
| 7581 | the ones without QuitOnClose), we emit the lastWindowClosed | ||
| 7582 | signal */ | ||
| 7584 | 7583 | QWidgetList list = QApplication::topLevelWidgets(); | |
| 7585 | 7584 | bool lastWindowClosed = true; | |
| 7586 | 7585 | for (int i = 0; i < list.size(); ++i) { | |
| 7587 | 7586 | QWidget *w = list.at(i); | |
| 7588 | if ((w->isVisible() && !w->testAttribute(Qt::WA_DontShowOnScreen)) | ||
| 7589 | && !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) { | ||
| 7590 | lastWindowClosed = false; | ||
| 7591 | break; | ||
| 7592 | } | ||
| 7587 | if (!w->isVisible() || w->parentWidget() || !w->testAttribute(Qt::WA_QuitOnClose)) | ||
| 7588 | continue; | ||
| 7589 | lastWindowClosed = false; | ||
| 7590 | break; | ||
| 7593 | 7591 | } | |
| 7594 | 7592 | if (lastWindowClosed) | |
| 7595 | 7593 | QApplicationPrivate::emitLastWindowClosed(); |
|   | |||
| 706 | 706 | QSignalSpy spy(&app, SIGNAL(aboutToQuit())); | |
| 707 | 707 | QSignalSpy spy2(&timer, SIGNAL(timeout())); | |
| 708 | 708 | ||
| 709 | QPointer<QMainWindow> mainWindow = new QMainWindow; | ||
| 710 | QPointer<QWidget> invisibleTopLevelWidget = new QWidget; | ||
| 711 | invisibleTopLevelWidget->setAttribute(Qt::WA_DontShowOnScreen); | ||
| 712 | |||
| 713 | QVERIFY(app.quitOnLastWindowClosed()); | ||
| 714 | QVERIFY(mainWindow->testAttribute(Qt::WA_QuitOnClose)); | ||
| 715 | QVERIFY(invisibleTopLevelWidget->testAttribute(Qt::WA_QuitOnClose)); | ||
| 716 | QVERIFY(invisibleTopLevelWidget->testAttribute(Qt::WA_DontShowOnScreen)); | ||
| 717 | |||
| 718 | mainWindow->show(); | ||
| 719 | invisibleTopLevelWidget->show(); | ||
| 720 | |||
| 721 | timer.start(); | ||
| 722 | QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application | ||
| 723 | QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't | ||
| 724 | |||
| 725 | app.exec(); | ||
| 726 | |||
| 727 | QCOMPARE(spy.count(), 1); | ||
| 728 | QVERIFY(spy2.count() < 15); // Should be around 10 if closing caused the quit | ||
| 729 | } | ||
| 730 | { | ||
| 731 | int argc = 0; | ||
| 732 | QApplication app(argc, 0, QApplication::GuiServer); | ||
| 733 | QTimer timer; | ||
| 734 | timer.setInterval(100); | ||
| 735 | |||
| 736 | QSignalSpy spy(&app, SIGNAL(aboutToQuit())); | ||
| 737 | QSignalSpy spy2(&timer, SIGNAL(timeout())); | ||
| 738 | |||
| 739 | 709 | QPointer<CloseEventTestWindow> mainWindow = new CloseEventTestWindow; | |
| 740 | 710 | ||
| 741 | 711 | QVERIFY(app.quitOnLastWindowClosed()); |

