本文整理汇总了C++中QMetaMethod::typeName方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaMethod::typeName方法的具体用法?C++ QMetaMethod::typeName怎么用?C++ QMetaMethod::typeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaMethod
的用法示例。
在下文中一共展示了QMetaMethod::typeName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getReturnType
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 )
示例2: listInterface
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");
}
}
示例3: doCallMethod
/*!
Function for executing a slot that does not take parameters
*/
QString ObjectService::doCallMethod(TasCommand* command, QObject* target, QString& errorString)
{
Q_ASSERT(command->name() == "CallMethod");
QString methodName = command->parameter("method_name");
TasLogger::logger()->debug("name: " + methodName);
int methodId = target->metaObject()->indexOfMethod(
QMetaObject::normalizedSignature(methodName.toLatin1()).constData());
if (methodId == -1){
errorString.append(methodName + " method not found on object. ");
TasLogger::logger()->debug("...method not found on object");
}
else{
QMetaMethod metaMethod = target->metaObject()->method(methodId);
QVariantList args = parseArguments(command);
QList<QGenericArgument> arguments;
for (int i = 0; i < args.size(); i++) {
QVariant& argument = args[i];
QGenericArgument genericArgument(
QMetaType::typeName(argument.userType()),
const_cast<void*>(argument.constData()));
arguments << genericArgument;
}
QVariant returnValue(QMetaType::type(metaMethod.typeName()),
static_cast<void*>(NULL));
QGenericReturnArgument returnArgument(
metaMethod.typeName(),
const_cast<void*>(returnValue.constData()));
if (!metaMethod.invoke(
target,
Qt::AutoConnection, // In case the object is in another thread.
returnArgument,
arguments.value(0),
arguments.value(1),
arguments.value(2),
arguments.value(3),
arguments.value(4),
arguments.value(5),
arguments.value(6),
arguments.value(7),
arguments.value(8),
arguments.value(9))) {
errorString.append(methodName + " method invocation failed! ");
} else {
return returnValue.toString();
}
}
return QString("");
}
示例4: doCall
// based on https://gist.github.com/andref/2838534.
bool JsonRpcServer::doCall(QObject* object,
const QMetaMethod& meta_method,
QVariantList& converted_args,
QVariant& return_value)
{
QList<QGenericArgument> arguments;
for (int i = 0; i < converted_args.size(); i++) {
// Notice that we have to take a reference to the argument, else we'd be
// pointing to a copy that will be destroyed when this loop exits.
QVariant& argument = converted_args[i];
// A const_cast is needed because calling data() would detach the
// QVariant.
QGenericArgument generic_argument(
QMetaType::typeName(argument.userType()),
const_cast<void*>(argument.constData())
);
arguments << generic_argument;
}
const char* return_type_name = meta_method.typeName();
int return_type = QMetaType::type(return_type_name);
if (return_type != QMetaType::Void) {
return_value = QVariant(return_type, nullptr);
}
QGenericReturnArgument return_argument(
return_type_name,
const_cast<void*>(return_value.constData())
);
// perform the call
bool ok = meta_method.invoke(
object,
Qt::DirectConnection,
return_argument,
arguments.value(0),
arguments.value(1),
arguments.value(2),
arguments.value(3),
arguments.value(4),
arguments.value(5),
arguments.value(6),
arguments.value(7),
arguments.value(8),
arguments.value(9)
);
if (!ok) {
// qDebug() << "calling" << meta_method.methodSignature() << "failed.";
return false;
}
logInfo(logInvoke(meta_method, converted_args, return_value));
return true;
}
示例5: queryQSObject
QSObject QSAEditor::queryQSObject( const QMetaObject *meta, const QString &property, bool /*includeSuperClass*/ ) const
{
int propertyIndex = -1;
const QMetaObject *m = meta;
propertyIndex = m->indexOfProperty(property.toLatin1().constData());
if (propertyIndex >= 0) {
QMetaProperty mp = m->property(propertyIndex);
QSObject o = vTypeToQSType( QString::fromLatin1(mp.typeName()) );
if ( !o.isNull() && !o.isUndefined() )
return o;
}
m = meta;
for (int i=0; i<m->methodCount(); ++i) {
QMetaMethod mm = m->method(i);
if (mm.methodType() == QMetaMethod::Slot) {
QString n = QLatin1String(mm.methodSignature());
n = n.left(n.indexOf('('));
if ( property != n )
continue;
return vTypeToQSType(mm.typeName());
}
}
return env()->createUndefined();
}
示例6: retType
const QMetaObject *QSAEditor::queryQMetaObject( const QMetaObject *meta,
const QString &property,
bool /*includeSuperClass*/ ) const
{
const QMetaObject *m = meta;
for (int i=0; i<m->methodCount(); ++i) {
QMetaMethod mm = m->method(i);
if (mm.methodType() == QMetaMethod::Slot) {
QString n = QLatin1String(mm.methodSignature());
n = n.left(n.indexOf('('));
if (property != n)
continue ;
QByteArray retType(mm.typeName());
if (retType.count('*') == 1) {
extern const QMetaObject *qsa_query_meta_object(const QByteArray &name);
return qsa_query_meta_object(qsa_strip_stars(retType));
}
}
}
return 0;
}
示例7: unwrapSmoke
extern "C" SEXP qt_qmocMethods(SEXP x) {
const QMetaObject *meta = unwrapSmoke(x, QMetaObject);
int n = meta->methodCount();
SEXP ans, ans_type, ans_signature, ans_return, ans_nargs;
PROTECT(ans = allocVector(VECSXP, 4));
ans_type = allocVector(INTSXP, n);
SET_VECTOR_ELT(ans, 0, ans_type);
ans_signature = allocVector(STRSXP, n);
SET_VECTOR_ELT(ans, 1, ans_signature);
ans_return = allocVector(STRSXP, n);
SET_VECTOR_ELT(ans, 2, ans_return);
ans_nargs = allocVector(INTSXP, n);
SET_VECTOR_ELT(ans, 3, ans_nargs);
for (int i = 0; i < n; i++) {
QMetaMethod metaMethod = meta->method(i);
INTEGER(ans_type)[i] = metaMethod.methodType();
SET_STRING_ELT(ans_signature, i, mkChar(metaMethod.signature()));
SET_STRING_ELT(ans_return, i, mkChar(metaMethod.typeName()));
INTEGER(ans_nargs)[i] = metaMethod.parameterNames().size();
}
UNPROTECT(1);
return ans;
}
示例8: while
void QDeclarativePropertyCache::Data::lazyLoad(const QMetaMethod &m)
{
coreIndex = m.methodIndex();
relatedIndex = -1;
flags |= Data::IsFunction;
if (m.methodType() == QMetaMethod::Signal)
flags |= Data::IsSignal;
propType = QVariant::Invalid;
const char *returnType = m.typeName();
if (returnType && *returnType) {
propTypeName = returnType;
flags |= Data::NotFullyResolved;
}
const char *signature = m.signature();
while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
++signature;
if (*signature != ')') {
flags |= Data::HasArguments;
if (0 == ::strcmp(signature, "QDeclarativeV8Function*)")) {
flags |= Data::IsV8Function;
}
}
revision = m.revision();
}
示例9: sig
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);
}
示例10: getStringValue
QString QbMySQLMappingHelper::getStringValue(QbPersistable &object, QMetaMethod method)
{
QString returnValue = "";
QString typeName = method.typeName();
if(!typeName.compare("int", Qt::CaseInsensitive)) {
int memberValue;
QMetaObject::invokeMethod(&object, method.name(), Q_RETURN_ARG(int, memberValue));
returnValue = QString::number(memberValue);
}
示例11: metacall
int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv)
{
Q_Q(QDBusInterface);
if (c == QMetaObject::InvokeMetaMethod) {
int offset = metaObject->methodOffset();
QMetaMethod mm = metaObject->method(id + offset);
if (mm.methodType() == QMetaMethod::Signal) {
// signal relay from D-Bus world to Qt world
QMetaObject::activate(q, metaObject, id, argv);
} else if (mm.methodType() == QMetaMethod::Slot || mm.methodType() == QMetaMethod::Method) {
// method call relay from Qt world to D-Bus world
// get D-Bus equivalent signature
QString methodName = QLatin1String(metaObject->dbusNameForMethod(id));
const int *inputTypes = metaObject->inputTypesForMethod(id);
int inputTypesCount = *inputTypes;
// we will assume that the input arguments were passed correctly
QVariantList args;
int i = 1;
for ( ; i <= inputTypesCount; ++i)
args << QVariant(inputTypes[i], argv[i]);
// make the call
QDBusMessage reply = q->callWithArgumentList(QDBus::Block, methodName, args);
if (reply.type() == QDBusMessage::ReplyMessage) {
// attempt to demarshall the return values
args = reply.arguments();
QVariantList::ConstIterator it = args.constBegin();
const int *outputTypes = metaObject->outputTypesForMethod(id);
int outputTypesCount = *outputTypes++;
if (*mm.typeName()) {
// this method has a return type
if (argv[0] && it != args.constEnd())
copyArgument(argv[0], *outputTypes++, *it);
// skip this argument even if we didn't copy it
--outputTypesCount;
++it;
}
for (int j = 0; j < outputTypesCount && it != args.constEnd(); ++i, ++j, ++it) {
copyArgument(argv[i], outputTypes[j], *it);
}
}
// done
lastError = reply;
return -1;
}
}
return id;
}
示例12: toVariantMap
QVariantMap SyncableObject::toVariantMap()
{
QVariantMap properties;
const QMetaObject *meta = metaObject();
// we collect data from properties
QMetaProperty prop;
QString propName;
for (int i = 0; i < meta->propertyCount(); i++) {
prop = meta->property(i);
propName = QString(prop.name());
if (propName == "objectName")
continue;
properties[propName] = prop.read(this);
}
// ...as well as methods, which have names starting with "init"
for (int i = 0; i < meta->methodCount(); i++) {
QMetaMethod method = meta->method(i);
QString methodname(SignalProxy::ExtendedMetaObject::methodName(method));
if (!methodname.startsWith("init") || methodname.startsWith("initSet") || methodname.startsWith("initDone"))
continue;
QVariant::Type variantType = QVariant::nameToType(method.typeName());
if (variantType == QVariant::Invalid && !QByteArray(method.typeName()).isEmpty()) {
#if QT_VERSION >= 0x050000
qWarning() << "SyncableObject::toVariantMap(): cannot fetch init data for:" << this << method.methodSignature() << "- Returntype is unknown to Qt's MetaSystem:" << QByteArray(method.typeName());
#else
qWarning() << "SyncableObject::toVariantMap(): cannot fetch init data for:" << this << method.signature() << "- Returntype is unknown to Qt's MetaSystem:" << QByteArray(method.typeName());
#endif
continue;
}
QVariant value(variantType, (const void *)0);
QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), value.data());
QMetaObject::invokeMethod(this, methodname.toLatin1(), genericvalue);
properties[SignalProxy::ExtendedMetaObject::methodBaseName(method)] = value;
}
return properties;
}
示例13:
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()});
}
示例14: NPClass_Invoke
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;
}
示例15: NPClass_Invoke
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;
}