diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2020-09-15 18:06:40 +0300 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2020-09-16 19:26:02 +0300 |
commit | 2180b4c84aacfcfcc2bc5a255a4a51be65e38551 (patch) | |
tree | ace021b3f6dd6496b062c5bc4f32fc57fdddaf52 /tests/auto/corelib | |
parent | ada01394dd02f7373bb2104fd16e6662a1873126 (diff) |
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 <oswald.buddenhagen@gmx.de>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp | 40 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h | 3 |
2 files changed, 43 insertions, 0 deletions
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 <private/qeventloop_p.h> #include <private/qthread_p.h> +#ifdef Q_OS_WIN +#include <QtCore/qt_windows.h> +#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<char*>(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(); |