本文整理汇总了C++中QMetaMethod::name方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaMethod::name方法的具体用法?C++ QMetaMethod::name怎么用?C++ QMetaMethod::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaMethod
的用法示例。
在下文中一共展示了QMetaMethod::name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateInterfaceXml
static QString generateInterfaceXml(const QMetaObject *mo, int flags, int methodOffset, int propOffset)
{
QString retval;
// start with properties:
if (flags & (QDBusConnection::ExportScriptableProperties |
QDBusConnection::ExportNonScriptableProperties)) {
for (int i = propOffset; i < mo->propertyCount(); ++i) {
static const char *accessvalues[] = {0, "read", "write", "readwrite"};
QMetaProperty mp = mo->property(i);
if (!((mp.isScriptable() && (flags & QDBusConnection::ExportScriptableProperties)) ||
(!mp.isScriptable() && (flags & QDBusConnection::ExportNonScriptableProperties))))
continue;
int access = 0;
if (mp.isReadable())
access |= 1;
if (mp.isWritable())
access |= 2;
int typeId = mp.userType();
if (!typeId)
continue;
const char *signature = QDBusMetaType::typeToSignature(typeId);
if (!signature)
continue;
retval += QString::fromLatin1(" <property name=\"%1\" type=\"%2\" access=\"%3\"")
.arg(QLatin1String(mp.name()))
.arg(QLatin1String(signature))
.arg(QLatin1String(accessvalues[access]));
if (QDBusMetaType::signatureToType(signature) == QVariant::Invalid) {
const char *typeName = QMetaType::typeName(typeId);
retval += QString::fromLatin1(">\n <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"%3\"/>\n </property>\n")
.arg(typeNameToXml(typeName));
} else {
retval += QLatin1String("/>\n");
}
}
}
// now add methods:
for (int i = methodOffset; i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
bool isSignal;
if (mm.methodType() == QMetaMethod::Signal)
// adding a signal
isSignal = true;
else if (mm.access() == QMetaMethod::Public && (mm.methodType() == QMetaMethod::Slot || mm.methodType() == QMetaMethod::Method))
isSignal = false;
else
continue; // neither signal nor public slot
if (isSignal && !(flags & (QDBusConnection::ExportScriptableSignals |
QDBusConnection::ExportNonScriptableSignals)))
continue; // we're not exporting any signals
if (!isSignal && (!(flags & (QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportNonScriptableSlots)) &&
!(flags & (QDBusConnection::ExportScriptableInvokables | QDBusConnection::ExportNonScriptableInvokables))))
continue; // we're not exporting any slots or invokables
QString xml = QString::fromLatin1(" <%1 name=\"%2\">\n")
.arg(isSignal ? QLatin1String("signal") : QLatin1String("method"))
.arg(QString::fromLatin1(mm.name()));
// check the return type first
int typeId = mm.returnType();
if (typeId != QMetaType::UnknownType && typeId != QMetaType::Void) {
const char *typeName = QDBusMetaType::typeToSignature(typeId);
if (typeName) {
xml += QString::fromLatin1(" <arg type=\"%1\" direction=\"out\"/>\n")
.arg(typeNameToXml(typeName));
// do we need to describe this argument?
if (QDBusMetaType::signatureToType(typeName) == QVariant::Invalid)
xml += QString::fromLatin1(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n")
.arg(typeNameToXml(QMetaType::typeName(typeId)));
} else {
qWarning() << "Unsupported return type" << typeId << QMetaType::typeName(typeId) << "in method" << mm.name();
continue;
}
}
else if (typeId == QMetaType::UnknownType) {
qWarning() << "Invalid return type in method" << mm.name();
continue; // wasn't a valid type
}
QList<QByteArray> names = mm.parameterNames();
QVector<int> types;
QString errorMsg;
int inputCount = qDBusParametersForMethod(mm, types, errorMsg);
if (inputCount == -1) {
qWarning() << "Skipped method" << mm.name() << ":" << qPrintable(errorMsg);
continue; // invalid form
}
if (isSignal && inputCount + 1 != types.count())
continue; // signal with output arguments?
//.........这里部分代码省略.........
示例2: method
void tst_QMetaMethod::method()
{
QFETCH(QByteArray, signature);
QFETCH(int, returnType);
QFETCH(QByteArray, returnTypeName);
QFETCH(QList<int>, parameterTypes);
QFETCH(QList<QByteArray>, parameterTypeNames);
QFETCH(QList<QByteArray>, parameterNames);
QFETCH(QMetaMethod::MethodType, methodType);
QFETCH(QMetaMethod::Access, access);
QVERIFY(parameterTypes.size() == parameterTypeNames.size());
QVERIFY(parameterTypes.size() == parameterNames.size());
const QMetaObject *mo = &MethodTestObject::staticMetaObject;
int index = (methodType == QMetaMethod::Constructor)
? mo->indexOfConstructor(signature) : mo->indexOfMethod(signature);
QVERIFY(index != -1);
QMetaMethod method = (methodType == QMetaMethod::Constructor)
? mo->constructor(index) : mo->method(index);
QVERIFY(method.isValid());
QCOMPARE(method.methodType(), methodType);
QCOMPARE(method.access(), access);
QVERIFY(!method.methodSignature().isEmpty());
if (method.methodSignature() != signature) {
// QMetaMethod should always produce a semantically equivalent signature
int signatureIndex = (methodType == QMetaMethod::Constructor)
? mo->indexOfConstructor(method.methodSignature())
: mo->indexOfMethod(method.methodSignature());
QCOMPARE(signatureIndex, index);
}
QByteArray computedName = signature.left(signature.indexOf('('));
QCOMPARE(method.name(), computedName);
QCOMPARE(method.tag(), "");
QCOMPARE(method.returnType(), returnType);
QVERIFY(method.typeName() != 0);
if (QByteArray(method.typeName()) != returnTypeName) {
// QMetaMethod should always produce a semantically equivalent typename
QCOMPARE(QMetaType::type(method.typeName()), QMetaType::type(returnTypeName));
}
if (method.parameterTypes() != parameterTypeNames) {
// QMetaMethod should always produce semantically equivalent typenames
QList<QByteArray> actualTypeNames = method.parameterTypes();
QCOMPARE(actualTypeNames.size(), parameterTypeNames.size());
for (int i = 0; i < parameterTypeNames.size(); ++i) {
QCOMPARE(QMetaType::type(actualTypeNames.at(i)),
QMetaType::type(parameterTypeNames.at(i)));
}
}
QCOMPARE(method.parameterNames(), parameterNames);
QCOMPARE(method.parameterCount(), parameterTypes.size());
for (int i = 0; i < parameterTypes.size(); ++i)
QCOMPARE(method.parameterType(i), parameterTypes.at(i));
{
QVector<int> actualParameterTypes(parameterTypes.size());
method.getParameterTypes(actualParameterTypes.data());
for (int i = 0; i < parameterTypes.size(); ++i)
QCOMPARE(actualParameterTypes.at(i), parameterTypes.at(i));
}
// Bogus indexes
QCOMPARE(method.parameterType(-1), 0);
QCOMPARE(method.parameterType(parameterTypes.size()), 0);
}
示例3: introspect
QVariantMap JsonHandler::introspect(QMetaMethod::MethodType type)
{
QVariantMap data;
for (int i = 0; i < metaObject()->methodCount(); ++i) {
QMetaMethod method = metaObject()->method(i);
if (method.methodType() != type) {
continue;
}
switch (method.methodType()) {
case QMetaMethod::Method: {
if (!m_descriptions.contains(method.name()) || !m_params.contains(method.name()) || !m_returns.contains(method.name())) {
continue;
}
qCDebug(dcJsonRpc) << "got method" << method.name();
QVariantMap methodData;
methodData.insert("description", m_descriptions.value(method.name()));
methodData.insert("params", m_params.value(method.name()));
methodData.insert("returns", m_returns.value(method.name()));
data.insert(name() + "." + method.name(), methodData);
break;
}
case QMetaMethod::Signal: {
if (!m_descriptions.contains(method.name()) || !m_params.contains(method.name())) {
continue;
}
if (QString(method.name()).contains(QRegExp("^[A-Z]"))) {
qCDebug(dcJsonRpc) << "got signal" << method.name();
QVariantMap methodData;
methodData.insert("description", m_descriptions.value(method.name()));
methodData.insert("params", m_params.value(method.name()));
data.insert(name() + "." + method.name(), methodData);
}
break;
default:
;;// Nothing to do for slots
}
}
}
return data;
}
示例4: property
void tst_QQmlMetaObject::property()
{
QFETCH(QString, testFile);
QFETCH(QByteArray, cppTypeName);
QFETCH(int, cppType);
QFETCH(bool, isDefault);
QFETCH(QVariant, expectedValue);
QFETCH(bool, isWritable);
QFETCH(QVariant, newValue);
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl(testFile));
QObject *object = component.create();
QVERIFY(object != 0);
const QMetaObject *mo = object->metaObject();
QVERIFY(mo->superClass() != 0);
QVERIFY(QByteArray(mo->className()).contains("_QML_"));
QCOMPARE(mo->propertyOffset(), mo->superClass()->propertyCount());
QCOMPARE(mo->propertyCount(), mo->superClass()->propertyCount() + 1);
QMetaProperty prop = mo->property(mo->propertyOffset());
QCOMPARE(prop.name(), "test");
QCOMPARE(QByteArray(prop.typeName()), cppTypeName);
if (prop.userType() < QMetaType::User)
QCOMPARE(prop.type(), QVariant::Type(cppType));
else
QCOMPARE(prop.type(), QVariant::UserType);
QCOMPARE(prop.userType(), cppType);
QVERIFY(!prop.isConstant());
QVERIFY(!prop.isDesignable());
QVERIFY(!prop.isEnumType());
QVERIFY(!prop.isFinal());
QVERIFY(!prop.isFlagType());
QVERIFY(prop.isReadable());
QVERIFY(!prop.isResettable());
QVERIFY(prop.isScriptable());
QVERIFY(!prop.isStored());
QVERIFY(!prop.isUser());
QVERIFY(prop.isValid());
QCOMPARE(prop.isWritable(), isWritable);
QCOMPARE(mo->classInfoOffset(), mo->superClass()->classInfoCount());
QCOMPARE(mo->classInfoCount(), mo->superClass()->classInfoCount() + (isDefault ? 1 : 0));
if (isDefault) {
QMetaClassInfo info = mo->classInfo(mo->classInfoOffset());
QCOMPARE(info.name(), "DefaultProperty");
QCOMPARE(info.value(), "test");
}
QCOMPARE(mo->methodOffset(), mo->superClass()->methodCount());
QCOMPARE(mo->methodCount(), mo->superClass()->methodCount() + 1); // the signal
QVERIFY(prop.notifySignalIndex() != -1);
QMetaMethod signal = prop.notifySignal();
QCOMPARE(signal.methodType(), QMetaMethod::Signal);
QCOMPARE(signal.name(), QByteArray("testChanged"));
QCOMPARE(signal.methodSignature(), QByteArray("testChanged()"));
QCOMPARE(signal.access(), QMetaMethod::Public);
QCOMPARE(signal.parameterCount(), 0);
QCOMPARE(signal.parameterTypes(), QList<QByteArray>());
QCOMPARE(signal.parameterNames(), QList<QByteArray>());
QCOMPARE(signal.tag(), "");
QCOMPARE(signal.typeName(), "void");
QCOMPARE(signal.returnType(), int(QMetaType::Void));
QSignalSpy changedSpy(object, SIGNAL(testChanged()));
QObject::connect(object, SIGNAL(testChanged()), object, SLOT(deleteLater()));
if (expectedValue.isValid())
QCOMPARE(prop.read(object), expectedValue);
else
QVERIFY(prop.read(object).isValid());
QCOMPARE(changedSpy.count(), 0);
if (isWritable) {
QVERIFY(prop.write(object, newValue));
QCOMPARE(changedSpy.count(), 1);
QCOMPARE(prop.read(object), newValue);
} else {
QVERIFY(!prop.write(object, prop.read(object)));
QCOMPARE(changedSpy.count(), 0);
}
delete object;
}
示例5: metaCall
int GoValueMetaObject::metaCall(QMetaObject::Call c, int idx, void **a)
{
switch (c) {
case QMetaObject::ReadProperty:
case QMetaObject::WriteProperty:
{
// TODO Cache propertyOffset, methodOffset, and qmlEngine results?
if (idx < propertyOffset()) {
return value->qt_metacall(c, idx, a);
}
GoMemberInfo *memberInfo = valuePriv->typeInfo->fields;
for (int i = 0; i < valuePriv->typeInfo->fieldsLen; i++) {
if (memberInfo->metaIndex == idx) {
if (c == QMetaObject::ReadProperty) {
DataValue result;
hookGoValueReadField(qmlEngine(value), valuePriv->addr, memberInfo->reflectIndex, &result);
QVariant *out = reinterpret_cast<QVariant *>(a[0]);
unpackDataValue(&result, out);
} else {
DataValue assign;
QVariant *in = reinterpret_cast<QVariant *>(a[0]);
packDataValue(in, &assign);
hookGoValueWriteField(qmlEngine(value), valuePriv->addr, memberInfo->reflectIndex, &assign);
}
return -1;
}
memberInfo++;
}
QMetaProperty prop = property(idx);
qWarning() << "Property" << prop.name() << "not found!?";
break;
}
case QMetaObject::InvokeMetaMethod:
{
if (idx < methodOffset()) {
return value->qt_metacall(c, idx, a);
}
GoMemberInfo *memberInfo = valuePriv->typeInfo->methods;
for (int i = 0; i < valuePriv->typeInfo->methodsLen; i++) {
if (memberInfo->metaIndex == idx) {
// args[0] is the result if any.
DataValue args[1 + MaxParams];
for (int i = 1; i < memberInfo->numIn+1; i++) {
packDataValue(reinterpret_cast<QVariant *>(a[i]), &args[i]);
}
hookGoValueCallMethod(qmlEngine(value), valuePriv->addr, memberInfo->reflectIndex, args);
if (memberInfo->numOut > 0) {
unpackDataValue(&args[0], reinterpret_cast<QVariant *>(a[0]));
}
return -1;
}
memberInfo++;
}
QMetaMethod m = method(idx);
qWarning() << "Method" << m.name() << "not found!?";
break;
}
default:
break; // Unhandled.
}
return -1;
}
示例6: clone
static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd)
{
// Set classname
builder.setClassName(ignoreEnd->className());
// Clone Q_CLASSINFO
for (int ii = mo->classInfoOffset(); ii < mo->classInfoCount(); ++ii) {
QMetaClassInfo info = mo->classInfo(ii);
int otherIndex = ignoreEnd->indexOfClassInfo(info.name());
if (otherIndex >= ignoreStart->classInfoOffset() + ignoreStart->classInfoCount()) {
// Skip
} else {
builder.addClassInfo(info.name(), info.value());
}
}
// Clone Q_PROPERTY
for (int ii = mo->propertyOffset(); ii < mo->propertyCount(); ++ii) {
QMetaProperty property = mo->property(ii);
int otherIndex = ignoreEnd->indexOfProperty(property.name());
if (otherIndex >= ignoreStart->propertyOffset() + ignoreStart->propertyCount()) {
builder.addProperty(QByteArray("__qml_ignore__") + property.name(), QByteArray("void"));
// Skip
} else {
builder.addProperty(property);
}
}
// Clone Q_METHODS
for (int ii = mo->methodOffset(); ii < mo->methodCount(); ++ii) {
QMetaMethod method = mo->method(ii);
// More complex - need to search name
QByteArray name = method.name();
bool found = false;
for (int ii = ignoreStart->methodOffset() + ignoreStart->methodCount();
!found && ii < ignoreEnd->methodOffset() + ignoreEnd->methodCount();
++ii) {
QMetaMethod other = ignoreEnd->method(ii);
found = name == other.name();
}
QMetaMethodBuilder m = builder.addMethod(method);
if (found) // SKIP
m.setAccess(QMetaMethod::Private);
}
// Clone Q_ENUMS
for (int ii = mo->enumeratorOffset(); ii < mo->enumeratorCount(); ++ii) {
QMetaEnum enumerator = mo->enumerator(ii);
int otherIndex = ignoreEnd->indexOfEnumerator(enumerator.name());
if (otherIndex >= ignoreStart->enumeratorOffset() + ignoreStart->enumeratorCount()) {
// Skip
} else {
builder.addEnumerator(enumerator);
}
}
}
示例7: exportItem
QString AsemanQtTools::exportItem(const QString &module, int major, int minor, const QString &component, bool store)
{
QString result;
aseman_qt_tools_indexCache << component;
QMetaObject meta = T::staticMetaObject;
QString inherits = fixType(meta.superClass()? meta.superClass()->className() : "");
bool isModel = component.toLower().contains("model");
result += QString("# %1\n\n").arg(component);
QString headers;
headers += QString(" * [Component details](#component-details)\n");
QString details = QString("\n### Component details:\n\n");
details += QString("|Detail|Value|\n"
"|------|-----|\n");
details += QString("|%1|%2 %3.%4|\n").arg("Import").arg(module).arg(major).arg(minor);
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Component").arg(component);
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("C++ class").arg(meta.className());
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Inherits").arg(inherits);
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Model").arg(isModel?"Yes":"No");
QString resultProperties;
QStringList propertiesSignals;
for(int i=0; i<meta.propertyCount(); i++)
{
QMetaProperty property = meta.property(i);
const QString &propertyName = property.name();
const QString &propertyType = fixType(property.typeName());
propertiesSignals << property.notifySignal().name();
QString text = QString("* <font color='#074885'><b>%1</b></font>: %2").arg(propertyName).arg(propertyType);
if(!property.isWritable())
text += " (readOnly)";
text += "\n";
if(meta.propertyOffset()<=i)
resultProperties += text;
}
QString enumResults;
for(int i=meta.enumeratorOffset(); i<meta.enumeratorCount(); i++)
{
QMetaEnum enumerator = meta.enumerator(i);
const QString &enumName = enumerator.name();
enumResults += QString("\n##### %1\n\n").arg(enumName);
enumResults += QString("|Key|Value|\n"
"|---|-----|\n");
for(int j=0; j<enumerator.keyCount(); j++)
enumResults += QString("|%1|%2|\n").arg(enumerator.key(j)).arg(enumerator.value(j));
}
QString resultSlots;
QString resultSignals;
for(int i=meta.methodOffset(); i<meta.methodCount(); i++)
{
QMetaMethod method = meta.method(i);
if(method.access() != QMetaMethod::Public)
continue;
const QString &methodName = method.name();
if(propertiesSignals.contains(methodName))
continue;
const QString &methodType = fixType(method.typeName());
QString args;
const QList<QByteArray> ¶mNames = method.parameterNames();
const QList<QByteArray> ¶mTypes = method.parameterTypes();
for(int j=0; j<paramNames.count(); j++)
{
if(j != 0)
args += ", ";
args += fixType(paramTypes[j]) + " " + paramNames[j];
}
QString text = QString(" * %1 <font color='#074885'><b>%2</b></font>(%3)\n").arg(methodType).arg(methodName).arg(args);
switch(static_cast<int>(method.methodType()))
{
case QMetaMethod::Slot:
resultSlots += text;
break;
case QMetaMethod::Signal:
resultSignals += text;
break;
}
}
if(!resultProperties.isEmpty())
{
headers += QString(" * [Normal Properties](#normal-properties)\n");
resultProperties = QString("\n### Normal Properties\n\n") + resultProperties;
}
if(!enumResults.isEmpty())
{
headers += QString(" * [Enumerator](#enumerator)\n");
//.........这里部分代码省略.........