Пример #1
0
bool QbElement::methodCompat(QMetaMethod method1, QMetaMethod method2)
{
    if (method1.parameterTypes() == method2.parameterTypes())
        return true;

    return false;
}
Пример #2
0
QByteArray MaiaXmlRpcServerConnection::getReturnType( const QMetaObject *obj,
                                                      const QByteArray &method,
                                                      const QList<QByteArray> &argTypes )
{
    for( int n = 0; n < obj->methodCount(); ++n ) {
        QMetaMethod m = obj->method(n);
#if QT_VERSION >= 0x050000
        if( m.name() == method && m.parameterTypes() == argTypes ) {
            return m.typeName();
        }
#else
        QByteArray sig = m.signature();

        int offset = sig.indexOf('(');
        if( offset == -1 ) {
            continue;
        }

        QByteArray name = sig.mid(0, offset);
        if( name == method && m.parameterTypes() == argTypes ) {
            return m.typeName();
        }
#endif
    }
    return QByteArray();

} // QByteArray getReturnType( const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> &argTypes )
Пример #3
0
    /*!
     * Creates a binding to the provided signal, slot, or Q_INVOKABLE method using the
     * provided parameter list. The type of each argument is deduced from the type of
     * the QVariant. This function cannot bind positional arguments; see the
     * overload using QGenericArgument.
     *
     * If the provided QObject does not implement the requested method, or if the
     * argument list is incompatible with the method's function signature, this
     * function returns NULL.
     *
     * The returned QxtBoundFunction is created as a child of the receiver.
     * Changing the parent will result in undefined behavior.
     *
     * \sa QxtMetaObject::connect, QxtBoundFunction
     */
    QxtBoundFunction* bind(QObject* recv, const char* invokable, QXT_IMPL_10ARGS(QVariant))
    {
        if (!recv)
        {
            qWarning() << "QxtMetaObject::bind: cannot connect to null QObject";
            return 0;
        }

        QVariant* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
        QByteArray connSlot("2"), recvSlot(QMetaObject::normalizedSignature(invokable));
        const QMetaObject* meta = recv->metaObject();
        int methodID = meta->indexOfMethod(QxtMetaObject::methodSignature(recvSlot.constData()));
        if (methodID == -1)
        {
            qWarning() << "QxtMetaObject::bind: no such method " << recvSlot;
            return 0;
        }
        QMetaMethod method = meta->method(methodID);
        int argCount = method.parameterTypes().count();
        const QList<QByteArray> paramTypes = method.parameterTypes();

        for (int i = 0; i < argCount; i++)
        {
            if (paramTypes[i] == "QxtBoundArgument") continue;
            int type = QMetaType::type(paramTypes[i].constData());
            if (!args[i]->canConvert((QVariant::Type)type))
            {
                qWarning() << "QxtMetaObject::bind: incompatible parameter list for " << recvSlot;
                return 0;
            }
        }

        return QxtMetaObject::bind(recv, invokable, QXT_ARG(1), QXT_ARG(2), QXT_ARG(3), QXT_ARG(4), QXT_ARG(5), QXT_ARG(6), QXT_ARG(7), QXT_ARG(8), QXT_ARG(9), QXT_ARG(10));
    }
Пример #4
0
        static inline bool methodCompat(const QMetaMethod &method1,
                                        const QMetaMethod &method2)
        {
            if (method1.parameterTypes() == method2.parameterTypes())
                return true;

            return false;
        }
static QString getDbusSignature(const QMetaMethod& method)
{
    // create a D-Bus type signature from QMetaMethod's parameters
    QString sig;
    for (int i = 0; i < method.parameterTypes().count(); ++i) {
        QVariant::Type type = QVariant::nameToType(method.parameterTypes().at(i));
        sig.append(QString::fromLatin1(QDBusMetaType::typeToSignature(type)));
    }
    return sig;
}
Пример #6
0
    /*!
     * Creates a binding to the provided signal, slot, or Q_INVOKABLE method using the
     * provided parameter list. Use the Q_ARG macro to specify constant parameters, or
     * use the QXT_BIND macro to relay a parameter from a connected signal or passed
     * via the QxtBoundFunction::invoke() method.
     *
     * If the provided QObject does not implement the requested method, or if the
     * argument list is incompatible with the method's function signature, this
     * function returns NULL.
     *
     * The returned QxtBoundFunction is created as a child of the receiver.
     * Changing the parent will result in undefined behavior.
     *
     * \sa QxtMetaObject::connect, QxtBoundFunction, QXT_BIND
     */
    QxtBoundFunction* bind(QObject* recv, const char* invokable, QXT_IMPL_10ARGS(QGenericArgument))
    {
        if (!recv)
        {
            qWarning() << "QxtMetaObject::bind: cannot connect to null QObject";
            return 0;
        }

        QGenericArgument* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
        QByteArray connSlot("2"), recvSlot(QMetaObject::normalizedSignature(invokable)), bindTypes[10];
        const QMetaObject* meta = recv->metaObject();
        int methodID = meta->indexOfMethod(QxtMetaObject::methodSignature(recvSlot.constData()).constData());
        if (methodID == -1)
        {
            qWarning() << "QxtMetaObject::bind: no such method " << recvSlot;
            return 0;
        }
        QMetaMethod method = meta->method(methodID);
        int argCount = method.parameterTypes().count();

        connSlot += QxtMetaObject::methodName(invokable) + '(';
        for (int i = 0; i < 10; i++)
        {
            if (args[i]->name() == 0) break;        // done
            if (i >= argCount)
            {
                qWarning() << "QxtMetaObject::bind: too many arguments passed to " << invokable;
                return 0;
            }
            if (i > 0) connSlot += ',';             // argument separator
            if (QByteArray(args[i]->name()) == "QxtBoundArgument")
            {
                Q_ASSERT_X((quintptr)(args[i]->data()) > 0 && (quintptr)(args[i]->data()) <= 10, "QXT_BIND", "invalid argument number");
                connSlot += method.parameterTypes()[i];
                bindTypes[i] = method.parameterTypes()[i];
            }
            else
            {
                connSlot += args[i]->name();        // type name
            }
        }
        connSlot = QMetaObject::normalizedSignature(connSlot += ')');

        if (!QMetaObject::checkConnectArgs(recvSlot.constData(), connSlot.constData()))
        {
            qWarning() << "QxtMetaObject::bind: provided parameters " << connSlot.mid(connSlot.indexOf('(')) << " is incompatible with " << invokable;
            return 0;
        }

        return new QxtBoundSlot(recv, invokable, args, bindTypes);
    }
void QJnextMainLoop::connect(QObject *object, uint id, QVariantList& args,
		QByteArray *retval) {
	QByteArray methodName = args.takeFirst().toByteArray();
	QByteArray sid = args.takeFirst().toByteArray();
	int argCount = -1;

	const QMetaObject* meta = object->metaObject();
	QMetaMethod method;
	for (int i = 0; i < meta->methodCount(); ++i) {
		method = meta->method(i);
		if (QByteArray(method.signature()).startsWith(methodName + "(")) {
			QList<QByteArray> types = method.parameterTypes();
			if (types.size() > argCount) {
				// TODO : always pick enum types
				argCount = method.parameterTypes().size();
				break;
			}
		}
	}
	if (argCount == -1) {
		*retval = "No signal named " + methodName + " found";
		return;
	}
#ifdef DEBUG_QJnextMainLoop
	qDebug() << "[QJnextMainLoop]\tSIGNAL.connect" << methodName << id << sid;
#endif

	QJnextUserData * jnextData = dynamic_cast<QJnextUserData*>(object->userData(
			QJnextMainLoop::userDataId));
	if (jnextData == NULL) {
		*retval = "Unable to retrieve jnextData from object "
				+ QByteArray::number(id);
		return;
	}

	SignalHandler *& handler = jnextData->signalHandlers[sid];
	if (handler != NULL) {
#ifdef DEBUG_QJnextMainLoop
		qDebug() << "[QJnextMainLoop]\tCONNECTED (chained)";
#endif
		return;
	}
	handler = new SignalHandler(this, object, id, "com.blackberry.qt" + sid, meta, method);
	if (!handler->isValid()) {
		*retval = "QMetaObject::connect returned false. Unable to connect";
		return;
	}
#ifdef DEBUG_QJnextMainLoop
	qDebug() << "[QJnextMainLoop]\tCONNECTED";
#endif
}
Пример #8
0
int /* search the meta data for a match to the name and args */
MocClass::findMethodId(Smoke *smoke, const QMetaObject *meta, const char *name,
                       SEXP args) const
{
  int result = -1;
  int classId = smoke->idClass(meta->className()).index;
  if (!args) return result; // Do not (yet?) support calls from Smoke
  while (classId == 0) {
    // go in reverse to choose most derived method first
    for (int id = meta->methodCount()-1; id >= 0; id--) {
      QMetaMethod meth = meta->method(id);
      if (meth.access() != QMetaMethod::Private) {
        QByteArray signature(meta->method(id).signature());
        QByteArray methodName = signature.mid(0, signature.indexOf('('));
        // Don't check that the types of the R args match
        // the c++ ones for now,
        // only that the name and arg count is the same.
        if (methodName == name &&
            meth.parameterTypes().count() == length(args))
          result = id;
      }
    }
    meta = meta->superClass();
    classId = smoke->idClass(meta->className()).index;
  }
  
  return result;
}
QDeclarativeObjectMethodScriptClass::Value 
QDeclarativeObjectMethodScriptClass::callPrecise(QObject *object, const QDeclarativePropertyCache::Data &data, 
                                                 QScriptContext *ctxt)
{
    if (data.flags & QDeclarativePropertyCache::Data::HasArguments) {

        QMetaMethod m = object->metaObject()->method(data.coreIndex);
        QList<QByteArray> argTypeNames = m.parameterTypes();
        QVarLengthArray<int, 9> argTypes(argTypeNames.count());

        // ### Cache
        for (int ii = 0; ii < argTypeNames.count(); ++ii) {
            argTypes[ii] = QMetaType::type(argTypeNames.at(ii));
            if (argTypes[ii] == QVariant::Invalid) 
                argTypes[ii] = enumType(object->metaObject(), QString::fromLatin1(argTypeNames.at(ii)));
            if (argTypes[ii] == QVariant::Invalid) 
                return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii)))));
        }

        if (argTypes.count() > ctxt->argumentCount())
            return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments")));

        return callMethod(object, data.coreIndex, data.propType, argTypes.count(), argTypes.data(), ctxt);

    } else {

        return callMethod(object, data.coreIndex, data.propType, 0, 0, ctxt);

    }
}
Пример #10
0
void InvokeMethod::on_comboMethods_activated(const QString &method)
{
    if (!activex)
	return;
    listParameters->clear();

    const QMetaObject *mo = activex->metaObject();
    const QMetaMethod slot = mo->method(mo->indexOfSlot(method.toLatin1()));
    QString signature = QString::fromLatin1(slot.signature());
    signature = signature.mid(signature.indexOf(QLatin1Char('(')) + 1);
    signature.truncate(signature.length()-1);

    QList<QByteArray> pnames = slot.parameterNames();
    QList<QByteArray> ptypes = slot.parameterTypes();

    for (int p = 0; p < ptypes.count(); ++p) {
	QString ptype(QString::fromLatin1(ptypes.at(p)));
	if (ptype.isEmpty())
	    continue;
	QString pname(QString::fromLatin1(pnames.at(p).constData()));
	if (pname.isEmpty())
	    pname = QString::fromLatin1("<unnamed %1>").arg(p);
	QTreeWidgetItem *item = new QTreeWidgetItem(listParameters);
        item->setText(0, pname);
        item->setText(1, ptype);
    }

    if (listParameters->topLevelItemCount())
	listParameters->setCurrentItem(listParameters->topLevelItem(0));
    editReturn->setText(QString::fromLatin1(slot.typeName()));
}
void QDBusViewer::callMethod(const BusSignature &sig)
{
    QDBusInterface iface(sig.mService, sig.mPath, sig.mInterface, c);
    const QMetaObject *mo = iface.metaObject();

    // find the method
    QMetaMethod method;
    for (int i = 0; i < mo->methodCount(); ++i) {
        const QString signature = QString::fromLatin1(mo->method(i).signature());
        if (signature.startsWith(sig.mName) && signature.at(sig.mName.length()) == QLatin1Char('('))
            if (getDbusSignature(mo->method(i)) == sig.mTypeSig)
                method = mo->method(i);
    }
    if (!method.signature()) {
        QMessageBox::warning(this, tr("Unable to find method"),
                tr("Unable to find method %1 on path %2 in interface %3").arg(
                    sig.mName).arg(sig.mPath).arg(sig.mInterface));
        return;
    }

    PropertyDialog dialog;
    QList<QVariant> args;

    const QList<QByteArray> paramTypes = method.parameterTypes();
    const QList<QByteArray> paramNames = method.parameterNames();
    QList<int> types; // remember the low-level D-Bus type
    for (int i = 0; i < paramTypes.count(); ++i) {
        const QByteArray paramType = paramTypes.at(i);
        if (paramType.endsWith('&'))
            continue; // ignore OUT parameters

        QVariant::Type type = QVariant::nameToType(paramType);
        dialog.addProperty(QString::fromLatin1(paramNames.value(i)), type);
        types.append(QMetaType::type(paramType));
    }

    if (!types.isEmpty()) {
        dialog.setInfo(tr("Please enter parameters for the method \"%1\"").arg(sig.mName));

        if (dialog.exec() != QDialog::Accepted)
            return;

        args = dialog.values();
    }

    // Special case - convert a value to a QDBusVariant if the
    // interface wants a variant
    for (int i = 0; i < args.count(); ++i) {
        if (types.at(i) == qMetaTypeId<QDBusVariant>())
            args[i] = qVariantFromValue(QDBusVariant(args.at(i)));
    }

    QDBusMessage message = QDBusMessage::createMethodCall(sig.mService, sig.mPath, sig.mInterface,
            sig.mName);
    message.setArguments(args);
    c.callWithCallback(message, this, SLOT(dumpMessage(QDBusMessage)));
}
Пример #12
0
static void qSignalDumperCallback(QObject *caller, int method_index, void **argv)
{
    Q_ASSERT(caller);
    Q_ASSERT(argv);
    Q_UNUSED(argv);
    const QMetaObject *mo = caller->metaObject();
    Q_ASSERT(mo);
    QMetaMethod member = mo->method(method_index);
    Q_ASSERT(member.signature());

    if (QTest::ignoreClasses() && QTest::ignoreClasses()->contains(mo->className())) {
        ++QTest::ignoreLevel;
        return;
    }

    QByteArray str;
    str.fill(' ', QTest::iLevel++ * QTest::IndentSpacesCount);
    str += "Signal: ";
    str += mo->className();
    str += '(';

    QString objname = caller->objectName();
    str += objname.toLocal8Bit();
    if (!objname.isEmpty())
        str += ' ';
    str += QByteArray::number(quintptr(caller), 16);

    str += ") ";
    str += QTest::memberName(member);
    str += " (";

    QList<QByteArray> args = member.parameterTypes();
    for (int i = 0; i < args.count(); ++i) {
        const QByteArray &arg = args.at(i);
        int typeId = QMetaType::type(args.at(i).constData());
        if (arg.endsWith('*') || arg.endsWith('&')) {
            str += '(';
            str += arg;
            str += ')';
            if (arg.endsWith('&'))
                str += '@';

            quintptr addr = quintptr(*reinterpret_cast<void **>(argv[i + 1]));
            str.append(QByteArray::number(addr, 16));
        } else if (typeId != QMetaType::Void) {
            str.append(arg)
            .append('(')
            .append(QVariant(typeId, argv[i + 1]).toString().toLocal8Bit())
            .append(')');
        }
        str.append(", ");
    }
    if (str.endsWith(", "))
        str.chop(2);
    str.append(')');
    qPrintMessage(str);
}
Пример #13
0
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};
}
Пример #14
0
    /**
     * \brief Extract the arguments types of a meta method
     *
     * \param metaMethod Qt meta method
     *
     * \return Arguments types of the meta method
     */
    static std::vector<ponder::Type> argTypes(const QMetaMethod& metaMethod)
    {
        std::vector<ponder::Type> types;

        QList<QByteArray> args = metaMethod.parameterTypes();
        Q_FOREACH(QByteArray arg, args)
        {
            types.push_back(QtHelper::type(arg));
        }
Пример #15
0
QString DataWidgetBinder::signature(QMetaMethod metaMethod) {
	QString str = metaMethod.name();
	str += "(";
	for(QByteArray t : metaMethod.parameterTypes()) {
		str += QString(t);
		str += "/";
	}
	str.chop(1);
	str += ")";
	return str;
}
Пример #16
0
QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::call(Object *o, QScriptContext *ctxt)
{
    MethodData *method = static_cast<MethodData *>(o);

    if (method->data.flags & QDeclarativePropertyCache::Data::HasArguments) {

        QMetaMethod m = method->object->metaObject()->method(method->data.coreIndex);
        QList<QByteArray> argTypeNames = m.parameterTypes();
        QVarLengthArray<int, 9> argTypes(argTypeNames.count());

        // ### Cache
        for (int ii = 0; ii < argTypeNames.count(); ++ii) {
            argTypes[ii] = QMetaType::type(argTypeNames.at(ii));
            if (argTypes[ii] == QVariant::Invalid)
                return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii)))));
        }

        if (argTypes.count() > ctxt->argumentCount())
            return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments")));

        QVarLengthArray<MetaCallArgument, 9> args(argTypes.count() + 1);
        args[0].initAsType(method->data.propType, engine);

        for (int ii = 0; ii < argTypes.count(); ++ii)
            args[ii + 1].fromScriptValue(argTypes[ii], engine, ctxt->argument(ii));

        QVarLengthArray<void *, 9> argData(args.count());
        for (int ii = 0; ii < args.count(); ++ii)
            argData[ii] = args[ii].dataPtr();

        QMetaObject::metacall(method->object, QMetaObject::InvokeMetaMethod, method->data.coreIndex, argData.data());

        return args[0].toValue(engine);

    } else if (method->data.propType != 0) {

        MetaCallArgument arg;
        arg.initAsType(method->data.propType, engine);

        void *args[] = { arg.dataPtr() };

        QMetaObject::metacall(method->object, QMetaObject::InvokeMetaMethod, method->data.coreIndex, args);

        return arg.toValue(engine);

    } else {

        void *args[] = { 0 };
        QMetaObject::metacall(method->object, QMetaObject::InvokeMetaMethod, method->data.coreIndex, args);
        return Value();

    }
    return Value();
}
void listInterface(const QString &service, const QString &path, const QString &interface)
{
    QDBusInterfacePtr iface(*connection, service, path, interface);
    if (!iface->isValid()) {
        QDBusError err(iface->lastError());
        fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n",
                qPrintable(interface), qPrintable(path), qPrintable(service),
                qPrintable(err.name()), qPrintable(err.message()));
        exit(1);
    }
    const QMetaObject *mo = iface->metaObject();

    // properties
    for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
        QMetaProperty mp = mo->property(i);
        printf("property ");

        if (mp.isReadable() && mp.isWritable())
            printf("readwrite");
        else if (mp.isReadable())
            printf("read");
        else
            printf("write");

        printf(" %s %s.%s\n", mp.typeName(), qPrintable(interface), mp.name());
    }

    // methods (signals and slots)
    for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
        QMetaMethod mm = mo->method(i);

        QByteArray signature = mm.signature();
        signature.truncate(signature.indexOf('('));
        printf("%s %s%s%s %s.%s(",
               mm.methodType() == QMetaMethod::Signal ? "signal" : "method",
               mm.tag(), *mm.tag() ? " " : "",
               *mm.typeName() ? mm.typeName() : "void",
               qPrintable(interface), signature.constData());

        QList<QByteArray> types = mm.parameterTypes();
        QList<QByteArray> names = mm.parameterNames();
        bool first = true;
        for (int i = 0; i < types.count(); ++i) {
            printf("%s%s",
                   first ? "" : ", ",
                   types.at(i).constData());
            if (!names.at(i).isEmpty())
                printf(" %s", names.at(i).constData());
            first = false;
        }
        printf(")\n");
    }
}
Пример #18
0
void QDeclarativePropertyCache::Data::load(const QMetaMethod &m)
{
    coreIndex = m.methodIndex();
    relatedIndex = -1;
    flags |= Data::IsFunction;
    if (m.methodType() == QMetaMethod::Signal)
        flags |= Data::IsSignal;
    propType = m.returnType();

    QList<QByteArray> params = m.parameterTypes();
    if (!params.isEmpty())
        flags |= Data::HasArguments;
    revision = m.revision();
}
Пример #19
0
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;
}
Пример #20
0
static bool NPClass_Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32 argCount, NPVariant *result)
{
    NPClass_Prolog;
    const QByteArray slotName = NPN_UTF8FromIdentifier(name);
    int slotIndex = publicMethodIndex(npobj, slotName, static_cast<int>(argCount));
    if (slotIndex == -1) {
        NPN_SetException(npobj, QByteArray("No method '" + slotName + "' with " + QByteArray::number(argCount) + " parameters").constData());
        return false;
    }

    const QMetaMethod slot = qobject->metaObject()->method(slotIndex);
    QList<QByteArray> parameterTypes = slot.parameterTypes();
    if (parameterTypes.count() != static_cast<int>(argCount)) {
        NPN_SetException(npobj, QByteArray("Wrong parameter count for method " + slotName).constData());
        return false;
    }

    QVariant returnVariant(QVariant::nameToType(slot.typeName()), (void*)0);
    QVector<QVariant> variants(parameterTypes.count()); // keep data alive
    QVector<const void*> metacallArgs(parameterTypes.count() + 1); // arguments for qt_metacall
    metacallArgs[0] = returnVariant.data(); // args[0] == return value

    for (int p = 0; p < parameterTypes.count(); ++p) {
        QVariant::Type type = QVariant::nameToType(parameterTypes.at(p));
        if (type == QVariant::Invalid && parameterTypes.at(p) != "QVariant") {
            NPN_SetException(npobj, QString("Parameter %1 in method '%2' has invalid type")
                .arg(p).arg(QString::fromUtf8(slotName)).toAscii().constData());
            return false;
        }
        QVariant qvar = args[p];
        if (type != QVariant::Invalid && !qvar.convert(type)) {
            NPN_SetException(npobj, QString("Parameter %1 to method '%2' needs to be convertable to '%3'")
                .arg(p).arg(QString::fromUtf8(slotName)).arg(QString::fromAscii(parameterTypes.at(p))).toAscii().constData());
            return false;
        }

        variants[p] = qvar;
        if (type == QVariant::Invalid)
            metacallArgs[p + 1] = &variants.at(p);
        else
            metacallArgs[p + 1] = variants.at(p).constData(); // must not detach!
    }

    qobject->qt_metacall(QMetaObject::InvokeMetaMethod, slotIndex, const_cast<void**>(metacallArgs.data()));
    if (returnVariant.isValid() && result)
        *result = NPVariant::fromQVariant(This, returnVariant);

    return true;
}
Пример #21
0
static int publicMethodIndex(NPObject *npobj, const QByteArray &slotName, int argCount = -1)
{
    NPClass_Prolog;
    const QMetaObject *metaObject = qobject->metaObject();
    for (int slotIndex = metaOffset(metaObject, MetaMethod); slotIndex < metaObject->methodCount(); ++slotIndex) {
        const QMetaMethod slot = qobject->metaObject()->method(slotIndex);
        if (slot.access() != QMetaMethod::Public || slot.methodType() == QMetaMethod::Signal)
            continue;
        QByteArray signature = slot.signature();
        if (signature.left(signature.indexOf('(')) == slotName) {
            if (argCount == -1 || slot.parameterTypes().count() == argCount)
                return slotIndex;
        }
    }
    return -1;
}
Пример #22
0
static bool NPClass_Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32 argCount, NPVariant *result)
{
    NPClass_Prolog;
    int slotIndex = publicMethodIndex(npobj, name);
    if (slotIndex == -1) {
        QByteArray qname = NPN_UTF8FromIdentifier(name);
        NPN_SetException(npobj, QByteArray("No such method " + qname).constData());
        return false;
    }

    const QMetaMethod slot = qobject->metaObject()->method(slotIndex);
    QList<QByteArray> parameterTypes = slot.parameterTypes();
    if (parameterTypes.count() != static_cast<int>(argCount)) {
        QByteArray qname = NPN_UTF8FromIdentifier(name);
        NPN_SetException(npobj, QByteArray("Wrong parameter count for method " + qname).constData());
        return false;
    }

    QVariant returnVariant(QVariant::nameToType(slot.typeName()), (void *)0);
    QVector<QVariant> variants(parameterTypes.count()); // keep data alive
    QVector<const void *> metacallArgs(parameterTypes.count() + 1); // arguments for qt_metacall
    metacallArgs[0] = returnVariant.data(); // args[0] == return value

    for (int p = 0; p < parameterTypes.count(); ++p) {
        QVariant::Type type = QVariant::nameToType(parameterTypes.at(p));
        if (type == QVariant::Invalid) {
            QByteArray qname = NPN_UTF8FromIdentifier(name);
            NPN_SetException(npobj, QByteArray("Unsupported parameter in method " + qname).constData());
            return false;
        }
        QVariant qvar = args[p];
        if (!qvar.convert(type)) {
            QByteArray qname = NPN_UTF8FromIdentifier(name);
            NPN_SetException(npobj, QByteArray("Unsupported parameter value in method " + qname).constData());
            return false;
        }

        variants[p] = qvar;
        metacallArgs[p + 1] = variants.at(p).constData(); // must not detach!
    }

    qobject->qt_metacall(QMetaObject::InvokeMetaMethod, slotIndex, const_cast<void * *>(metacallArgs.data()));
    if (returnVariant.isValid() && result)
        *result = NPVariant::fromQVariant(This, returnVariant);

    return true;
}
Пример #23
0
JSValue QtInstance::stringValue(ExecState* exec) const
{
    QObject* obj = getObject();
    if (!obj)
        return jsNull();

    // Hmm.. see if there is a toString defined
    QByteArray buf;
    bool useDefault = true;
    getClass();
    if (m_class) {
        // Cheat and don't use the full name resolution
        int index = obj->metaObject()->indexOfMethod("toString()");
        if (index >= 0) {
            QMetaMethod m = obj->metaObject()->method(index);
            // Check to see how much we can call it
            if (m.access() != QMetaMethod::Private
                && m.methodType() != QMetaMethod::Signal
                && m.parameterTypes().isEmpty()) {
                const char* retsig = m.typeName();
                if (retsig && *retsig) {
                    QVariant ret(QMetaType::type(retsig), (void*)0);
                    void * qargs[1];
                    qargs[0] = ret.data();

                    if (QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, index, qargs) < 0) {
                        if (ret.isValid() && ret.canConvert(QVariant::String)) {
                            buf = ret.toString().toLatin1().constData(); // ### Latin 1? Ascii?
                            useDefault = false;
                        }
                    }
                }
            }
        }
    }

    if (useDefault) {
        const QMetaObject* meta = obj ? obj->metaObject() : &QObject::staticMetaObject;
        QString name = obj ? obj->objectName() : QString::fromUtf8("unnamed");
        QString str = QString::fromUtf8("%0(name = \"%1\")")
                      .arg(QLatin1String(meta->className())).arg(name);

        buf = str.toLatin1();
    }
    return jsString(exec, buf.constData());
}
PythonQtMethodInfo::PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInfo* classInfo)
{
#ifdef PYTHONQT_DEBUG
  QByteArray sig(meta.signature());
  sig = sig.mid(sig.indexOf('('));
  QByteArray fullSig = QByteArray(meta.typeName()) + " " + sig;
  std::cout << "caching " << fullSig.data() << std::endl;
#endif

  ParameterInfo type;
  fillParameterInfo(type, QByteArray(meta.typeName()), classInfo);
  _parameters.append(type);
  QList<QByteArray> names = meta.parameterTypes();
  foreach (const QByteArray& name, names) {
    fillParameterInfo(type, name, classInfo);
    _parameters.append(type);
  }
Пример #25
0
static void getSlots( const QMetaObject *meta, QList<Property> &result,
		      bool super, bool withArgs, bool sigs )
{
    while (meta) {
        int nmethods = meta->methodCount();
        for (int i=0; i<nmethods; ++i) {
            const QMetaMethod m = meta->method(i);

            if (m.access() == QMetaMethod::Private)
                continue ;

            if ((m.methodType() == QMetaMethod::Slot && !sigs) ||
                (m.methodType() == QMetaMethod::Signal && sigs)) {
	            Property prop;
	            QString s = QLatin1String( m.methodSignature() );
	            s = s.left(s.indexOf('('));

                QList<QByteArray> parameterTypes = m.parameterTypes();
                QList<QByteArray> parameterNames = m.parameterNames();
                prop.type = m.typeName();
                QuickInterpreter::cleanType(prop.type);
	            if ( withArgs ) {
	                s += QLatin1String("(");

	                for ( int j = 0; j < parameterTypes.count(); ++j ) {
		                s += parameterTypes.at(j);
                        s += QLatin1String(" ");
		                s += QString::fromLatin1(parameterNames.at(j));
		                if ( j < parameterTypes.count() - 1 )
		                    s += QString::fromLatin1(",");
	                }
	                s += QString::fromLatin1(")");
	            }

	            prop.name = s;
	            if (result.indexOf(prop) == -1)
	                result << prop;
            }
        }

        if (super)
            meta = meta->superClass();
        else
            meta = 0;
    }
}
Пример #26
0
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;
}
QByteArray MaiaXmlRpcServerConnection::getReturnType(const QMetaObject *obj,
			const QByteArray &method, const QList<QByteArray> argTypes) {
	for(int n = 0; n < obj->methodCount(); ++n) {
		QMetaMethod m = obj->method(n);
		QByteArray sig = m.signature();
		int offset = sig.indexOf('(');
		if(offset == -1)
			continue;
		QByteArray name = sig.mid(0, offset);
		if(name != method)
			continue;
		if(m.parameterTypes() != argTypes)
			continue;

		return m.typeName();
	}
	return QByteArray();
}
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;
}
Пример #29
0
void QxtWebJsonRPCService::Private::initTables(QObject *in)
{
    invokable = in;
    const QMetaObject *po = invokable->metaObject();
    for (int i = po->methodOffset(); i < po->methodCount(); i++) {

        QxtWebJsonRPCService::Private::Method method;
        QMetaMethod mo = po->method (i);
#if QT_VERSION >=  0x50000
        method.name = QByteArray(mo.methodSignature()).split('(').at(0);
#else
        method.name = QByteArray(mo.signature()).split('(').at(0);
#endif
        method.meta = mo;
        method.argCount = mo.parameterTypes ().count();
        method.returns = QByteArray(mo.typeName()).count();
        methods.insert(method.name + QByteArray::number(method.argCount), method);
    }
}
Пример #30
0
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
}