标签:
static QString signatureFromJsonArray(const QJsonArray &array) { QStringList list; foreach(const QJsonValue &v, array) { list<<JSTypeToString(v.type()); } return list.join(","); }
static QString signatureFromMethod(const QMetaMethod &method) { QStringList list; for(int i=0; i<method.parameterCount(); i++) { int type = method.parameterType(i); list<<JSTypeToString(convertVariantTypeToJSType(type)); } return list.join(","); }
static QVariantList createParameterVariantList(const QMetaMethod &method, const QJsonArray &array) { QVariantList varList; for(int i=0; i<method.parameterCount(); i++) { int type = method.parameterType(i); QVariant v= convertJSValueToVariant(type, array.at(i)); varList.append(v); } return varList; } static QVariant invoke(QObject* object, const QMetaMethod &method, const QJsonArray ¶ms) { QVarLengthArray<void *, 10> invokeParams; //压入返回值,参数 int returnType = method.returnType(); if (returnType==QMetaType::Void) { returnType = QMetaType::UnknownType; } QVariant returnValue(returnType, nullptr); invokeParams.append(returnValue.data()); //压入参数 QVariantList varList = createParameterVariantList(method, params); foreach(const QVariant &v, varList) { invokeParams.append(const_cast<void *>(v.constData())); } //调用 object->qt_metacall(QMetaObject::InvokeMetaMethod, method.methodIndex(), invokeParams.data()); return returnValue; }
标签:
原文地址:http://www.cnblogs.com/danju/p/4861538.html