From 08101b2b27f7f2177993ddb62c15187c169ccd19 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 30 Apr 2019 14:13:22 +0200 Subject: [PATCH] Fix qplugin.h for Qt 6 Change-Id: I3ae6594a2982f990a5b3851a063b0b2f02d16bd9 Reviewed-by: Thiago Macieira --- src/corelib/plugin/qplugin.h | 32 +++++++++++++++---- .../qguiapplication/tst_qguiapplication.cpp | 4 +++ tests/auto/tools/moc/tst_moc.cpp | 11 +++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h index 676b5047d6..c176155c28 100644 --- a/src/corelib/plugin/qplugin.h +++ b/src/corelib/plugin/qplugin.h @@ -75,7 +75,12 @@ typedef QObject *(*QtPluginInstanceFunction)(); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) typedef const char *(*QtPluginMetaDataFunction)(); #else -typedef QPair (*QtPluginMetaDataFunction)(); +struct QPluginMetaData +{ + const uchar *data; + size_t size; +}; +typedef QPluginMetaData (*QtPluginMetaDataFunction)(); #endif @@ -84,12 +89,14 @@ struct Q_CORE_EXPORT QStaticPlugin #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) public: constexpr QStaticPlugin(QtPluginInstanceFunction i, QtPluginMetaDataFunction m) - : instance(i), rawMetaData(m().first), rawMetaDataSize(m().second) + : instance(i), rawMetaData(m().data), rawMetaDataSize(m().size) + {} QtPluginInstanceFunction instance; private: // ### Qt 6: revise, as this is not standard-layout const void *rawMetaData; - qsizetype rawMetaDataSize + qsizetype rawMetaDataSize; +public: #elif !defined(Q_QDOC) // Note: This struct is initialized using an initializer list. // As such, it cannot have any new constructors or variables. @@ -154,6 +161,16 @@ void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin); #if defined(QT_STATICPLUGIN) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +# define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \ + static QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGINCLASSNAME() \ + Q_PLUGIN_INSTANCE(PLUGINCLASS) \ + static QPluginMetaData qt_plugin_query_metadata_##PLUGINCLASSNAME() \ + { return { qt_pluginMetaData, sizeof qt_pluginMetaData }; } \ + const QT_PREPEND_NAMESPACE(QStaticPlugin) qt_static_plugin_##PLUGINCLASSNAME() { \ + return { qt_plugin_instance_##PLUGINCLASSNAME, qt_plugin_query_metadata_##PLUGINCLASSNAME}; \ + } +#else # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \ static QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGINCLASSNAME() \ Q_PLUGIN_INSTANCE(PLUGINCLASS) \ @@ -162,13 +179,15 @@ void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin); QT_PREPEND_NAMESPACE(QStaticPlugin) plugin = { qt_plugin_instance_##PLUGINCLASSNAME, qt_plugin_query_metadata_##PLUGINCLASSNAME}; \ return plugin; \ } +#endif -#elif QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#else +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \ Q_EXTERN_C Q_DECL_EXPORT \ - auto qt_plugin_query_metadata() \ - { return qMakePair(qt_pluginMetaData, sizeof qt_pluginMetaData); } \ + QPluginMetaData qt_plugin_query_metadata() \ + { return { qt_pluginMetaData, sizeof qt_pluginMetaData }; } \ Q_EXTERN_C Q_DECL_EXPORT QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance() \ Q_PLUGIN_INSTANCE(PLUGINCLASS) @@ -183,6 +202,7 @@ void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin); #endif +#endif #define Q_EXPORT_PLUGIN(PLUGIN) \ Q_EXPORT_PLUGIN2(PLUGIN, PLUGIN) diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index a304981cd1..09fec89de4 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -989,9 +989,13 @@ void tst_QGuiApplication::genericPluginsAndWindowSystemEvents() QCoreApplication::postEvent(&testReceiver, new QEvent(QEvent::User)); QCOMPARE(testReceiver.customEvents, 0); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QStaticPlugin testPluginInfo(qt_plugin_instance, qt_plugin_query_metadata); +#else QStaticPlugin testPluginInfo; testPluginInfo.instance = qt_plugin_instance; testPluginInfo.rawMetaData = qt_plugin_query_metadata; +#endif qRegisterStaticPluginFunction(testPluginInfo); int argc = 3; char *argv[] = { const_cast(QTest::currentAppName()), const_cast("-plugin"), const_cast("testplugin") }; diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index f12df578f4..6b7aaf7c0a 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -1425,6 +1425,16 @@ void tst_Moc::environmentIncludePaths() // plugin_metadata.h contains a plugin which we register here. Since we're not building this // application as a plugin, we need top copy some of the initializer code found in qplugin.h: extern "C" QObject *qt_plugin_instance(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +extern "C" QPluginMetaData qt_plugin_query_metadata(); +class StaticPluginInstance{ +public: + StaticPluginInstance() { + QStaticPlugin plugin(qt_plugin_instance, qt_plugin_query_metadata); + qRegisterStaticPluginFunction(plugin); + } +}; +#else extern "C" const char *qt_plugin_query_metadata(); class StaticPluginInstance{ public: @@ -1433,6 +1443,7 @@ public: qRegisterStaticPluginFunction(plugin); } }; +#endif static StaticPluginInstance staticInstance; void tst_Moc::specifyMetaTagsFromCmdline() {