emit lastWindowClosed even if quitOnLastWindowClosed is false
Behavior will agree with the docs. [ChangeLog][QtGui][QWindow] lastWindowClosed will be emitted even if quitOnLastWindowClosed is not set Task-number: QTBUG-32956 Change-Id: I7bb269d53894859fee27e171eea7ad472ea86af0 Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
This commit is contained in:
parent
7aadf03fea
commit
32422885fc
@ -2290,24 +2290,22 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed()
|
|||||||
Q_Q(QWindow);
|
Q_Q(QWindow);
|
||||||
// Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent
|
// Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent
|
||||||
bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent();
|
bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent();
|
||||||
|
QWindowList list = QGuiApplication::topLevelWindows();
|
||||||
if (quitOnClose) {
|
bool lastWindowClosed = true;
|
||||||
QWindowList list = QGuiApplication::topLevelWindows();
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
bool lastWindowClosed = true;
|
QWindow *w = list.at(i);
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
if (!w->isVisible() || w->transientParent())
|
||||||
QWindow *w = list.at(i);
|
continue;
|
||||||
if (!w->isVisible() || w->transientParent())
|
lastWindowClosed = false;
|
||||||
continue;
|
break;
|
||||||
lastWindowClosed = false;
|
}
|
||||||
break;
|
if (lastWindowClosed) {
|
||||||
}
|
QGuiApplicationPrivate::emitLastWindowClosed();
|
||||||
if (lastWindowClosed) {
|
if (quitOnClose) {
|
||||||
QGuiApplicationPrivate::emitLastWindowClosed();
|
|
||||||
QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance()));
|
QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance()));
|
||||||
applicationPrivate->maybeQuit();
|
applicationPrivate->maybeQuit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *QWindowPrivate::topLevelWindow() const
|
QWindow *QWindowPrivate::topLevelWindow() const
|
||||||
|
@ -812,6 +812,33 @@ void tst_QGuiApplication::quitOnLastWindowClosed()
|
|||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
QVERIFY(spy2.count() > 15); // Should be around 20 if closing did not cause the quit
|
QVERIFY(spy2.count() > 15); // Should be around 20 if closing did not cause the quit
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
QGuiApplication app(argc, 0);
|
||||||
|
app.setQuitOnLastWindowClosed(false);
|
||||||
|
|
||||||
|
QTimer timer;
|
||||||
|
timer.setInterval(2000);
|
||||||
|
timer.setSingleShot(true);
|
||||||
|
QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit()));
|
||||||
|
|
||||||
|
QSignalSpy spy(&app, SIGNAL(lastWindowClosed()));
|
||||||
|
QSignalSpy spy2(&timer, SIGNAL(timeout()));
|
||||||
|
|
||||||
|
QPointer<QWindow> mainWindow = new QWindow;
|
||||||
|
|
||||||
|
mainWindow->show();
|
||||||
|
|
||||||
|
QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should not quit the application
|
||||||
|
timer.start();
|
||||||
|
|
||||||
|
app.exec();
|
||||||
|
|
||||||
|
QCOMPARE(spy2.count(), 1); // quit timer fired
|
||||||
|
QCOMPARE(spy.count(), 1); // lastWindowClosed emitted
|
||||||
|
|
||||||
|
app.setQuitOnLastWindowClosed(true); // restore underlying static to default value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Qt::ScreenOrientation testOrientationToSend = Qt::PrimaryOrientation;
|
static Qt::ScreenOrientation testOrientationToSend = Qt::PrimaryOrientation;
|
||||||
|
Loading…
Reference in New Issue
Block a user