From 2180b4c84aacfcfcc2bc5a255a4a51be65e38551 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Tue, 15 Sep 2020 18:06:40 +0300 Subject: QEventDispatcherWin32: create internal window on construction When QCoreApplication object is instantiated, creation of the internal message window is delayed until QEventDispatcherWin32::processEvents() is called or socket/event notifier is registered. But, if the user uses a native event loop, posted events are not delivered and timers do not work. This problem was fixed in a4ac4b326318ed9034466305222280ed8d1651b5 for QWindowsGuiEventDispatcher in the same way. So, the risk of regression is minimal. Change-Id: I7bbb721d96046f64d21a7b0e553e46798b37189c Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira Reviewed-by: Friedemann Kleint --- .../qcoreapplication/tst_qcoreapplication.cpp | 40 ++++++++++++++++++++++ .../kernel/qcoreapplication/tst_qcoreapplication.h | 3 ++ 2 files changed, 43 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 8567d8c3b9..b9772f6922 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -36,6 +36,10 @@ #include #include +#ifdef Q_OS_WIN +#include +#endif + typedef QCoreApplication TestApplication; class EventSpy : public QObject @@ -617,6 +621,42 @@ void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() } while (t.elapsed() < 1000); } +#ifdef Q_OS_WIN +void tst_QCoreApplication::sendPostedEventsInNativeLoop() +{ + int argc = 1; + char *argv[] = { const_cast(QTest::currentAppName()) }; + TestApplication app(argc, argv); + + bool signalReceived = false; + + // Post a message to the queue + QMetaObject::invokeMethod(this, [&signalReceived]() { + signalReceived = true; + }, Qt::QueuedConnection); + + QElapsedTimer elapsedTimer; + elapsedTimer.start(); + + // Exec own message loop + MSG msg; + forever { + if (elapsedTimer.hasExpired(3000) || signalReceived) + break; + + if (!::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + QThread::msleep(100); + continue; + } + + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + QVERIFY(signalReceived); +} +#endif // Q_OS_WIN + class QuitBlocker : public QObject { Q_OBJECT diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h index b8475fd8c2..655a879afa 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h @@ -49,6 +49,9 @@ private slots: void applicationPid(); void globalPostedEventsCount(); void processEventsAlwaysSendsPostedEvents(); +#ifdef Q_OS_WIN + void sendPostedEventsInNativeLoop(); +#endif void quit(); void reexec(); void execAfterExit(); -- cgit v1.2.3