Fix qplugin.h for Qt 6

Change-Id: I3ae6594a2982f990a5b3851a063b0b2f02d16bd9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2019-04-30 14:13:22 +02:00
parent 82ddecfb17
commit 08101b2b27
3 changed files with 41 additions and 6 deletions

View File

@ -75,7 +75,12 @@ typedef QObject *(*QtPluginInstanceFunction)();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
typedef const char *(*QtPluginMetaDataFunction)(); typedef const char *(*QtPluginMetaDataFunction)();
#else #else
typedef QPair<const uchar *, size_t> (*QtPluginMetaDataFunction)(); struct QPluginMetaData
{
const uchar *data;
size_t size;
};
typedef QPluginMetaData (*QtPluginMetaDataFunction)();
#endif #endif
@ -84,12 +89,14 @@ struct Q_CORE_EXPORT QStaticPlugin
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
public: public:
constexpr QStaticPlugin(QtPluginInstanceFunction i, QtPluginMetaDataFunction m) constexpr QStaticPlugin(QtPluginInstanceFunction i, QtPluginMetaDataFunction m)
: instance(i), rawMetaData(m().first), rawMetaDataSize(m().second) : instance(i), rawMetaData(m().data), rawMetaDataSize(m().size)
{}
QtPluginInstanceFunction instance; QtPluginInstanceFunction instance;
private: private:
// ### Qt 6: revise, as this is not standard-layout // ### Qt 6: revise, as this is not standard-layout
const void *rawMetaData; const void *rawMetaData;
qsizetype rawMetaDataSize qsizetype rawMetaDataSize;
public:
#elif !defined(Q_QDOC) #elif !defined(Q_QDOC)
// Note: This struct is initialized using an initializer list. // Note: This struct is initialized using an initializer list.
// As such, it cannot have any new constructors or variables. // 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 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) \ # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \
static QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGINCLASSNAME() \ static QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGINCLASSNAME() \
Q_PLUGIN_INSTANCE(PLUGINCLASS) \ 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}; \ QT_PREPEND_NAMESPACE(QStaticPlugin) plugin = { qt_plugin_instance_##PLUGINCLASSNAME, qt_plugin_query_metadata_##PLUGINCLASSNAME}; \
return plugin; \ 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) \ # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \
Q_EXTERN_C Q_DECL_EXPORT \ Q_EXTERN_C Q_DECL_EXPORT \
auto qt_plugin_query_metadata() \ QPluginMetaData qt_plugin_query_metadata() \
{ return qMakePair<const void *, size_t>(qt_pluginMetaData, sizeof qt_pluginMetaData); } \ { return { qt_pluginMetaData, sizeof qt_pluginMetaData }; } \
Q_EXTERN_C Q_DECL_EXPORT QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance() \ Q_EXTERN_C Q_DECL_EXPORT QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance() \
Q_PLUGIN_INSTANCE(PLUGINCLASS) Q_PLUGIN_INSTANCE(PLUGINCLASS)
@ -183,6 +202,7 @@ void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin);
#endif #endif
#endif
#define Q_EXPORT_PLUGIN(PLUGIN) \ #define Q_EXPORT_PLUGIN(PLUGIN) \
Q_EXPORT_PLUGIN2(PLUGIN, PLUGIN) Q_EXPORT_PLUGIN2(PLUGIN, PLUGIN)

View File

@ -989,9 +989,13 @@ void tst_QGuiApplication::genericPluginsAndWindowSystemEvents()
QCoreApplication::postEvent(&testReceiver, new QEvent(QEvent::User)); QCoreApplication::postEvent(&testReceiver, new QEvent(QEvent::User));
QCOMPARE(testReceiver.customEvents, 0); 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; QStaticPlugin testPluginInfo;
testPluginInfo.instance = qt_plugin_instance; testPluginInfo.instance = qt_plugin_instance;
testPluginInfo.rawMetaData = qt_plugin_query_metadata; testPluginInfo.rawMetaData = qt_plugin_query_metadata;
#endif
qRegisterStaticPluginFunction(testPluginInfo); qRegisterStaticPluginFunction(testPluginInfo);
int argc = 3; int argc = 3;
char *argv[] = { const_cast<char*>(QTest::currentAppName()), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") }; char *argv[] = { const_cast<char*>(QTest::currentAppName()), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") };

View File

@ -1425,6 +1425,16 @@ void tst_Moc::environmentIncludePaths()
// plugin_metadata.h contains a plugin which we register here. Since we're not building this // 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: // application as a plugin, we need top copy some of the initializer code found in qplugin.h:
extern "C" QObject *qt_plugin_instance(); 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(); extern "C" const char *qt_plugin_query_metadata();
class StaticPluginInstance{ class StaticPluginInstance{
public: public:
@ -1433,6 +1443,7 @@ public:
qRegisterStaticPluginFunction(plugin); qRegisterStaticPluginFunction(plugin);
} }
}; };
#endif
static StaticPluginInstance staticInstance; static StaticPluginInstance staticInstance;
void tst_Moc::specifyMetaTagsFromCmdline() { void tst_Moc::specifyMetaTagsFromCmdline() {