From 4c71db756741d35ccb32dc4c32aa1823264c85df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 12 Mar 2015 14:00:52 +0100 Subject: QWindow::destroy(): only reset QGuiApp::focus_window and friends as a last resort MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resetting focus_window and other internal QGuiApplication variables before calling setVisible(false) and destroying the platform window means that the platform window can't reason about whether or not it was the focus window unless it can resolve that using native APIs. We should let the platform window take care of resetting the focus window and related states, and only execute our fallback logic if the plugin doesn't do the right thing. We also use QPA to update the state instead of modifying the internal QGuiApplication variables directly, so that events and signals are emitted as a result of the reset. The QLineEdit test gets two added calls to processEvents(), since assuming that activateWindow() is synchronous is not correct, and would result in the QMenu resetting the focus window to 0 on destroy. Task-number: QTBUG-46414 Change-Id: I562788393ed0ffd77d7a4be2279862322f721c1a Reviewed-by: Błażej Szczygieł Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 13 +++++++++++++ tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index a89f0da4d2..794d549b57 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -94,6 +94,7 @@ private slots: void modalWindowPosition(); void windowsTransientChildren(); void requestUpdate(); + void destroyResetsFocusWindow(); void initTestCase(); void stateChange_data(); void stateChange(); @@ -1804,6 +1805,18 @@ void tst_QWindow::requestUpdate() QTRY_COMPARE(window.received(QEvent::UpdateRequest), 2); } +void tst_QWindow::destroyResetsFocusWindow() +{ + QWindow window; + window.showNormal(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + QCOMPARE(qGuiApp->focusWindow(), &window); + + window.destroy(); + QVERIFY(!qGuiApp->focusWindow()); +} + #include QTEST_MAIN(tst_QWindow) diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index b46609c371..bf17625803 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3570,7 +3570,7 @@ void tst_QLineEdit::task174640_editingFinished() QVERIFY(QTest::qWaitForWindowExposed(testMenu1)); QTest::qWait(20); mw.activateWindow(); - + qApp->processEvents(); delete testMenu1; QCOMPARE(editingFinishedSpy.count(), 0); QTRY_VERIFY(le1->hasFocus()); @@ -3582,6 +3582,7 @@ void tst_QLineEdit::task174640_editingFinished() QVERIFY(QTest::qWaitForWindowExposed(testMenu2)); QTest::qWait(20); mw.activateWindow(); + qApp->processEvents(); delete testMenu2; QCOMPARE(editingFinishedSpy.count(), 1); } -- cgit v1.2.3