当前位置: 首页>>代码示例>>C++>>正文


C++ QMetaMethod::parameterCount方法代码示例

本文整理汇总了C++中QMetaMethod::parameterCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaMethod::parameterCount方法的具体用法?C++ QMetaMethod::parameterCount怎么用?C++ QMetaMethod::parameterCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QMetaMethod的用法示例。


在下文中一共展示了QMetaMethod::parameterCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: activateSignal

void Test::activateSignal(const QString &signal, const QVariantList &args)
{
    int metaIndex = d->signalName2Id.value(signal, -1);
    if (metaIndex == -1) {
        qWarning() << "dynamic signal" << signal << "doesn't exist";
        return;
    }

    QMetaMethod sig = d->meta->method(metaIndex);
    if (sig.parameterCount() != args.count()) {
        qWarning() << "dynamic signal has" << sig.parameterCount() << "args"
                   << args.count() << "provided";
        return;
    }

    QVariantList argsCopy = args;
    void * _a[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    for (int i = 0; i < sig.parameterCount(); ++i) {
        if (!argsCopy[i].convert(sig.parameterType(i))) {
            qWarning() << "dynamic signal" << signal << "wrong parameter" << i;
            return;
        }
        _a[i + 1] = argsCopy[i].data();
    }

    QMetaObject::activate(this, d->meta, metaIndex - d->meta->methodOffset(), _a);
}
开发者ID:romixlab,项目名称:trunk,代码行数:28,代码来源:test.cpp

示例2: qsignal

error *objectConnect(QObject_ *object, const char *signal, int signalLen, QQmlEngine_ *engine, void *func, int argsLen)
{
    QObject *qobject = reinterpret_cast<QObject *>(object);
    QQmlEngine *qengine = reinterpret_cast<QQmlEngine *>(engine);
    QByteArray qsignal(signal, signalLen);

    const QMetaObject *meta = qobject->metaObject();
    // Walk backwards so descendants have priority.
    for (int i = meta->methodCount()-1; i >= 0; i--) {
            QMetaMethod method = meta->method(i);
            if (method.methodType() == QMetaMethod::Signal) {
                QByteArray name = method.name();
                if (name.length() == signalLen && qstrncmp(name.constData(), signal, signalLen) == 0) {
                    if (method.parameterCount() < argsLen) {
                        // TODO Might continue looking to see if a different signal has the same name and enough arguments.
                        return errorf("signal \"%s\" has too few parameters for provided function", name.constData());
                    }
					Connector *connector = Connector::New(qobject, method, qengine, func, argsLen);
                    const QMetaObject *connmeta = connector->metaObject();
                    QObject::connect(qobject, method, connector, connmeta->method(connmeta->methodOffset()));
                    return 0;
                }
            }
    }
    // Cannot use constData here as the byte array is not null-terminated.
    return errorf("object does not expose a \"%s\" signal", qsignal.data());
}
开发者ID:chai2010,项目名称:qml,代码行数:27,代码来源:goqml.cpp

示例3: qt_metacall

int Test::qt_metacall(QMetaObject::Call call, int id, void **args)
{
    id = QObject::qt_metacall(call, id, args);
    if (id < 0 || !d->meta)
        return id;

    if (call == QMetaObject::InvokeMetaMethod) {
        int metaIndex = id + d->meta->methodOffset();
        QMetaMethod method = d->meta->method(metaIndex);
        if (!method.isValid()) {
            qWarning() << "invoked invalid method with id" << id;
            return -1;
        }
        QVariantList vargs;
        for (int i = 0; i < method.parameterCount(); ++i)
            vargs.append(QVariant(method.parameterType(i), args[1 + i]));
        QString catchedName = d->slotId2Name.value(metaIndex);
        void *_a[] = { 0,
                       const_cast<void*>(reinterpret_cast<const void*>(&catchedName)),
                       const_cast<void*>(reinterpret_cast<const void*>(&vargs)) };
        QMetaObject::activate(this, metaObject(), d->catchedSignalId, _a);
    }

    return -1;
}
开发者ID:romixlab,项目名称:trunk,代码行数:25,代码来源:test.cpp

示例4: metaMethodParamTypeIds

QVector<int> metaMethodParamTypeIds(QMetaMethod m) {
    QVector<int> ret;
    int maxCnt = m.parameterCount();
    for (int i = 0; i < maxCnt; i++) {
        ret.push_back(m.parameterType(i));
    }
    return ret;
}
开发者ID:robxu9,项目名称:qtjs-generator,代码行数:8,代码来源:callInfo.cpp

示例5: make_setter_method

setter_method make_setter_method(const types_by_name &known_types, const QMetaMethod &meta_method)
{
	auto parameter_type = meta_method.parameterCount() == 1
		? type_by_pointer(known_types, meta_method.parameterTypes()[0].data())
		: type{nullptr};
	setter_method::validate_setter_method(parameter_type, meta_method);

	return setter_method{parameter_type, meta_method};
}
开发者ID:ovz,项目名称:injeqt,代码行数:9,代码来源:setter-method.cpp

示例6:

factory_method::factory_method(type result_type, QMetaMethod meta_method) :
	_object_type{meta_method.enclosingMetaObject()},
	_result_type{std::move(result_type)},
	_meta_method{std::move(meta_method)}
{
	assert(meta_method.methodType() == QMetaMethod::Method || meta_method.methodType() == QMetaMethod::Slot);
	assert(meta_method.parameterCount() == 0);
	assert(meta_method.enclosingMetaObject() != nullptr);
	assert(!_result_type.is_empty());
	assert(_result_type.name() + "*" == std::string{meta_method.typeName()});
}
开发者ID:respu,项目名称:injeqt,代码行数:11,代码来源:factory-method.cpp

示例7: prettyMethodSignature

QString Util::prettyMethodSignature(const QMetaMethod& method)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
  return method.signature();
#else
  QString signature = method.typeName();
  signature += ' ' + method.name() + '(';
  QStringList args;
  args.reserve(method.parameterCount());
  const QList<QByteArray> paramTypes = method.parameterTypes();
  const QList<QByteArray> paramNames = method.parameterNames();
  for (int i = 0; i < method.parameterCount(); ++i) {
    QString arg = paramTypes.at(i);
    if (!paramNames.at(i).isEmpty())
      arg += ' ' + paramNames.at(i);
    args.push_back(arg);
  }
  signature += args.join(QStringLiteral(", ")) + ')';
  return signature;
#endif
}
开发者ID:SBGSports,项目名称:GammaRay,代码行数:21,代码来源:util.cpp

示例8: bind

void QFSignalProxy::bind(QObject *source, int signalIdx, QQmlEngine* engine, QFDispatcher* dispatcher)
{
    const int memberOffset = QObject::staticMetaObject.methodCount();

    QMetaMethod method = source->metaObject()->method(signalIdx);

    parameterTypes = QVector<int>(method.parameterCount());
    parameterNames = QVector<QString>(method.parameterCount());
    type = method.name();
    m_engine = engine;
    m_dispatcher = dispatcher;

    for (int i = 0 ; i < method.parameterCount() ; i++) {
        parameterTypes[i] = method.parameterType(i);
        parameterNames[i] = QString(method.parameterNames().at(i));
    }

    if (!QMetaObject::connect(source, signalIdx, this, memberOffset, Qt::AutoConnection, 0)) {
        qWarning() << "Failed to bind signal";
    }
}
开发者ID:SunRain,项目名称:quickflux,代码行数:21,代码来源:qfsignalproxy.cpp

示例9: convertArgs

bool JsonRpcServer::convertArgs(const QMetaMethod& meta_method,
                                const QVariantMap& args,
                                QVariantList& converted_args)
{
    QList<QByteArray> param_types = meta_method.parameterTypes();
    if (args.size() != param_types.size()) {
        logError(QString("wrong number of arguments to method %1 -- "
                         "expected %2 arguments, but got %3")
                 .arg(QString(meta_method.methodSignature()))
                 .arg(meta_method.parameterCount())
                 .arg(args.size()));
        return false;
    }

    for (int i = 0; i < param_types.size(); i++) {
        QByteArray param_name = meta_method.parameterNames().at(i);
        if (args.find(param_name) == args.end()) {
            // no arg with param name found
            return false;
        }
        const QVariant& arg = args.value(param_name);
        if (!arg.isValid()) {
            logError(QString("argument %1 of %2 to method %3 is invalid")
                     .arg(i + 1)
                     .arg(param_types.size())
                     .arg(QString(meta_method.methodSignature())));
            return false;
        }

        QByteArray arg_type_name = arg.typeName();
        QByteArray param_type_name = param_types.at(i);

        QVariant::Type param_type = QVariant::nameToType(param_type_name);

        QVariant copy = QVariant(arg);

        if (copy.type() != param_type) {
            if (copy.canConvert(param_type)) {
                if (!copy.convert(param_type)) {
                    // qDebug() << "cannot convert" << arg_type_name
                    //          << "to" << param_type_name;
                    return false;
                }
            }
        }

        converted_args << copy;
    }
    return true;
}
开发者ID:joncol,项目名称:jcon-cpp,代码行数:50,代码来源:json_rpc_server.cpp

示例10: qt_metacall

	int DynamicQObject::qt_metacall(QMetaObject::Call call, int id, void **arguments)
	{
printf("%d\n", call);
		// Call default handlers in QObject first
		id = QObject::qt_metacall(call, id, arguments);
		if (id == -1 || call != QMetaObject::InvokeMetaMethod)
			return id;

#if 0
		Q_ASSERT(id < callbacks.count());
		Callback *callback = callbacks[id];

		int methodId = findSignalId(callback->signal);

		// Convert parameters
		HandleScope scope;

		const QMetaObject *meta = obj->metaObject();
		QMetaMethod method = meta->method(methodId);
		int argc = method.parameterCount();

		Handle<Value> *argv = new Handle<Value>[argc];
		for (int i = 0; i < method.parameterCount(); ++i) {
			int type = method.parameterType(i);

			// Convert
			argv[i] = Utils::QDataToV8(type, arguments[i + 1]);
		}

		// Invoke
		MakeCallback(callback->handler, callback->handler, argc, argv);

		// Release
		delete [] argv;
#endif
		return -1;
	}
开发者ID:swhgoon,项目名称:brig,代码行数:37,代码来源:DynamicQObject.cpp

示例11: errorf

error *objectInvoke(QObject_ *object, const char *method, int methodLen, DataValue *resultdv, DataValue *paramsdv, int paramsLen)
{
    QObject *qobject = reinterpret_cast<QObject *>(object);

    QVariant result;
    QVariant param[MaxParams];
    QGenericArgument arg[MaxParams];
    for (int i = 0; i < paramsLen; i++) {
        unpackDataValue(&paramsdv[i], &param[i]);
        arg[i] = Q_ARG(QVariant, param[i]);
    }
    if (paramsLen > 10) {
        panicf("fix the parameter dispatching");
    }

    const QMetaObject *metaObject = qobject->metaObject();
    // Walk backwards so descendants have priority.
    for (int i = metaObject->methodCount()-1; i >= 0; i--) {
        QMetaMethod metaMethod = metaObject->method(i);
        QMetaMethod::MethodType methodType = metaMethod.methodType();
        if (methodType == QMetaMethod::Method || methodType == QMetaMethod::Slot) {
            QByteArray name = metaMethod.name();
            if (name.length() == methodLen && qstrncmp(name.constData(), method, methodLen) == 0) {
                if (metaMethod.parameterCount() < paramsLen) {
                    // TODO Might continue looking to see if a different signal has the same name and enough arguments.
                    return errorf("method \"%s\" has too few parameters for provided arguments", method);
                }

                bool ok;
                if (metaMethod.returnType() == QMetaType::Void) {
                    ok = metaMethod.invoke(qobject, Qt::DirectConnection, 
                        arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]);
                } else {
                    ok = metaMethod.invoke(qobject, Qt::DirectConnection, Q_RETURN_ARG(QVariant, result),
                        arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]);
                }
                if (!ok) {
                    return errorf("invalid parameters to method \"%s\"", method);
                }

                packDataValue(&result, resultdv);
                return 0;
            }
        }
    }

    return errorf("object does not expose a method \"%s\"", method);
}
开发者ID:chai2010,项目名称:qml,代码行数:48,代码来源:goqml.cpp

示例12: validate_action_method

bool action_method::validate_action_method(const QMetaMethod &meta_method)
{
	auto meta_object = meta_method.enclosingMetaObject();
	if (!meta_object)
		throw exception::invalid_action{std::string{"action does not have enclosing meta object: "} + "?::" + meta_method.methodSignature().data()};
	if (meta_method.methodType() == QMetaMethod::Signal)
		throw exception::invalid_action{std::string{"action is signal: "} + meta_object->className() + "::" + meta_method.methodSignature().data()};
	if (meta_method.methodType() == QMetaMethod::Constructor)
		throw exception::invalid_action{std::string{"action is constructor: "} + meta_object->className() + "::" + meta_method.methodSignature().data()};
	if (!is_action_init_tag(meta_method.tag()) && !is_action_done_tag(meta_method.tag()))
		throw exception::invalid_action{std::string{"action does not have valid tag: "} + meta_object->className() + "::" + meta_method.methodSignature().data()};
	if (meta_method.parameterCount() != 0)
		throw exception::invalid_action{std::string{"invalid parameter count: "} + meta_object->className() + "::" + meta_method.methodSignature().data()};

	return true;
}
开发者ID:ovz,项目名称:injeqt,代码行数:16,代码来源:action-method.cpp

示例13: fromMethodToCallbackFlag

QString ExtendedBase::fromMethodToCallbackFlag(const QMetaMethod &method)
{
    QString buf;

    buf += method.name();
    buf += "(";
    for(auto index = 0; index < method.parameterCount(); index++)
    {
        if(index)
        {
            buf += ",";
        }
        buf += method.parameterTypes()[index];
    }
    buf += ")";

    return buf;
}
开发者ID:188080501,项目名称:JasonQt_Sjf,代码行数:18,代码来源:JasonQt_SjfDevice.cpp

示例14: method

void tst_QQmlMetaObject::method()
{
    QFETCH(QString, testFile);
    QFETCH(QString, signature);
    QFETCH(QMetaMethod::MethodType, methodType);
    QFETCH(int, returnType);
    QFETCH(QString, returnTypeName);
    QFETCH(QList<int>, parameterTypes);
    QFETCH(QList<QByteArray>, parameterTypeNames);
    QFETCH(QList<QByteArray>, parameterNames);

    QCOMPARE(parameterTypes.size(), parameterTypeNames.size());
    QCOMPARE(parameterTypeNames.size(), parameterNames.size());

    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->methodOffset(), mo->superClass()->methodCount());
    QCOMPARE(mo->methodCount(), mo->superClass()->methodCount() + 1);

    QMetaMethod method = mo->method(mo->methodOffset());
    QCOMPARE(method.methodType(), methodType);
    QCOMPARE(QString::fromUtf8(method.methodSignature().constData()), signature);
    QCOMPARE(method.access(), QMetaMethod::Public);

    QString computedName = signature.left(signature.indexOf('('));
    QCOMPARE(QString::fromUtf8(method.name()), computedName);

    QCOMPARE(method.parameterCount(), parameterTypes.size());
    for (int i = 0; i < parameterTypes.size(); ++i)
        QCOMPARE(method.parameterType(i), parameterTypes.at(i));
    QCOMPARE(method.parameterTypes(), parameterTypeNames);
    QCOMPARE(method.tag(), "");

    QCOMPARE(QString::fromUtf8(method.typeName()), returnTypeName);
    QCOMPARE(method.returnType(), returnType);

    delete object;
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:44,代码来源:tst_qqmlmetaobject.cpp

示例15: checkParameterCount

void Bindable::checkParameterCount(const QMetaMethod &method, const int paramCount)
{
	Q_ASSERT_X(method.parameterCount() == paramCount, "Bindable::wait",
			   qPrintable(QString("Incompatible argument count (expected %1, got %2)")
							  .arg(method.parameterCount(), paramCount)));
}
开发者ID:02JanDal,项目名称:LogicalGui,代码行数:6,代码来源:LogicalGui.cpp


注:本文中的QMetaMethod::parameterCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。