diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 8659c4c1f6..419403d938 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -905,7 +905,7 @@ void QGuiApplicationPrivate::init() is_app_running = true; init_plugins(pluginList); - QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents); + QWindowSystemInterface::flushWindowSystemEvents(); } extern void qt_cleanupFontDatabase(); diff --git a/tests/auto/gui/kernel/qguiapplication/testplugin.json b/tests/auto/gui/kernel/qguiapplication/testplugin.json new file mode 100644 index 0000000000..25c587807c --- /dev/null +++ b/tests/auto/gui/kernel/qguiapplication/testplugin.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "testplugin" ] +} diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index de5e049289..82d1b17dad 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -61,6 +62,7 @@ private slots: void keyboardModifiers(); void modalWindow(); void quitOnLastWindowClosed(); + void genericPluginsAndWindowSystemEvents(); }; void tst_QGuiApplication::displayName() @@ -568,6 +570,74 @@ void tst_QGuiApplication::quitOnLastWindowClosed() } } +static Qt::ScreenOrientation testOrientationToSend = Qt::PrimaryOrientation; + +class TestPlugin : public QObject +{ + Q_OBJECT +public: + TestPlugin() + { + QScreen* screen = QGuiApplication::primaryScreen(); + // Make sure the orientation we want to send doesn't get filtered out. + screen->setOrientationUpdateMask(screen->orientationUpdateMask() | testOrientationToSend); + QWindowSystemInterface::handleScreenOrientationChange(screen, testOrientationToSend); + } +}; + +class TestPluginFactory : public QGenericPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "testplugin.json") +public: + QObject* create(const QString &key, const QString &) + { + if (key == "testplugin") + return new TestPlugin; + return 0; + } +}; + +class TestEventReceiver : public QObject +{ + Q_OBJECT +public: + int customEvents; + + TestEventReceiver() + : customEvents(0) + {} + + virtual void customEvent(QEvent *) + { + customEvents++; + } +}; + +#include "tst_qguiapplication.moc" + +void tst_QGuiApplication::genericPluginsAndWindowSystemEvents() +{ + testOrientationToSend = Qt::InvertedLandscapeOrientation; + + TestEventReceiver testReceiver; + QCoreApplication::postEvent(&testReceiver, new QEvent(QEvent::User)); + QCOMPARE(testReceiver.customEvents, 0); + + QStaticPlugin testPluginInfo; + testPluginInfo.instance = qt_plugin_instance; + testPluginInfo.metaData = qt_plugin_query_metadata; + qRegisterStaticPluginFunction(testPluginInfo); + int argc = 3; + char *argv[] = { const_cast("tst_qguiapplication"), const_cast("-plugin"), const_cast("testplugin") }; + QGuiApplication app(argc, argv); + + QVERIFY(QGuiApplication::primaryScreen()); + QVERIFY(QGuiApplication::primaryScreen()->orientation() == testOrientationToSend); + + QCOMPARE(testReceiver.customEvents, 0); + QCoreApplication::sendPostedEvents(&testReceiver); + QCOMPARE(testReceiver.customEvents, 1); +} QTEST_APPLESS_MAIN(tst_QGuiApplication) -#include "tst_qguiapplication.moc"