从 QMetaObject 检索 QMetaType

retrieve QMetaType from QMetaObject

我有一个遍历 Qt 插件元数据的递归函数。从 QMetaType 获取 QMetaObject 很简单,但是我找不到任何可以让我从 QMetaObject 获取 QMetaType 的东西。请看下面的例子:

QPluginLoader pluginLoader(pluginPath);
const QMetaObject *pMetaObject = pluginInstance->metaObject();
//how do I get the metatype? in the meantime as I move forward
auto metaMethod = pMetaObject->method(pMetaObject->methodOffset());//QMetaMethod
int returnType = metaMethod.returnType();
auto qMetaType = QMetaType(returnType);//QMetaType for custom class obtained

我的插件条目 class 和我的方法 returns 的其他自定义 class 都已使用 qRegisterMetaType() 注册。

int id = QMetaType::type(pMetaObject->className());
if (id != QMetaType::UnknownType)
{
    QMetaType metaType(id);
    ...
}