?? qmetaobject.cpp
字號:
int i = -1; const QMetaObject *m = this; while (m && i < 0) { for (i = priv(m->d.data)->propertyCount-1; i >= 0; --i) if (strcmp(name, m->d.stringdata + m->d.data[priv(m->d.data)->propertyData + 3*i]) == 0) { i += m->propertyOffset(); break; } m = m->d.superdata; } return i;}/*! Finds class information item \a name and returns its index; otherwise returns -1. \sa classInfo(), classInfoCount(), classInfoOffset()*/int QMetaObject::indexOfClassInfo(const char *name) const{ int i = -1; const QMetaObject *m = this; while (m && i < 0) { for (i = priv(m->d.data)->classInfoCount-1; i >= 0; --i) if (strcmp(name, m->d.stringdata + m->d.data[priv(d.data)->classInfoData + 2*i]) == 0) { i += m->classInfoOffset(); break; } m = m->d.superdata; } return i;}/*! Returns the meta-data for the method with the given \a index. \sa methodCount(), methodOffset(), indexOfMethod()*/QMetaMethod QMetaObject::method(int index) const{ int i = index; i -= methodOffset(); if (i < 0 && d.superdata) return d.superdata->method(index); QMetaMethod result; if (i >= 0 && i < priv(d.data)->methodCount) { result.mobj = this; result.handle = priv(d.data)->methodData + 5*i; } return result;}/*! Returns the meta-data for the enumerator with the given \a index. \sa enumeratorCount(), enumeratorOffset(), indexOfEnumerator()*/QMetaEnum QMetaObject::enumerator(int index) const{ int i = index; i -= enumeratorOffset(); if (i < 0 && d.superdata) return d.superdata->enumerator(index); QMetaEnum result; if (i >= 0 && i < priv(d.data)->enumeratorCount) { result.mobj = this; result.handle = priv(d.data)->enumeratorData + 4*i; } return result;}/*! Returns the meta-data for the property with the given \a index. If no such property exists, a null QMetaProperty is returned. \sa propertyCount(), propertyOffset(), indexOfProperty()*/QMetaProperty QMetaObject::property(int index) const{ int i = index; i -= propertyOffset(); if (i < 0 && d.superdata) return d.superdata->property(index); QMetaProperty result; if (i >= 0 && i < priv(d.data)->propertyCount) { int handle = priv(d.data)->propertyData + 3*i; int flags = d.data[handle + 2]; const char *type = d.stringdata + d.data[handle + 1]; result.mobj = this; result.handle = handle; result.idx = i; if (flags & EnumOrFlag) { result.menum = enumerator(indexOfEnumerator(type)); if (!result.menum.isValid()) { QByteArray enum_name = type; QByteArray scope_name = d.stringdata; int s = enum_name.lastIndexOf("::"); if (s > 0) { scope_name = enum_name.left(s); enum_name = enum_name.mid(s + 2); } const QMetaObject *scope = 0; if (scope_name == "Qt") scope = &QObject::staticQtMetaObject; else scope = QMetaObject_findMetaObject(this, scope_name); if (scope) result.menum = scope->enumerator(scope->indexOfEnumerator(enum_name)); } } } return result;}/*! \since 4.2 Returns the property that has the \c USER flag set to true. \sa QMetaProperty::isUser()*/QMetaProperty QMetaObject::userProperty() const{ const int propCount = propertyCount(); for (int i = propCount - 1; i >= 0; --i) { const QMetaProperty prop = property(i); if (prop.isUser()) return prop; } return QMetaProperty();}/*! Returns the meta-data for the item of class information with the given \a index. Example: \code class MyClass { Q_OBJECT Q_CLASSINFO("author", "Sabrina Schweinsteiger") Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") public: ... }; \endcode \sa classInfoCount(), classInfoOffset(), indexOfClassInfo() */QMetaClassInfo QMetaObject::classInfo(int index) const{ int i = index; i -= classInfoOffset(); if (i < 0 && d.superdata) return d.superdata->classInfo(index); QMetaClassInfo result; if (i >= 0 && i < priv(d.data)->classInfoCount) { result.mobj = this; result.handle = priv(d.data)->classInfoData + 2*i; } return result;}/*! Returns true if the \a signal and \a method arguments are compatible; otherwise returns false. Both \a signal and \a method are expected to be normalized. \sa normalizedSignature()*/bool QMetaObject::checkConnectArgs(const char *signal, const char *method){ const char *s1 = signal; const char *s2 = method; while (*s1++ != '(') { } // scan to first '(' while (*s2++ != '(') { } if (*s2 == ')' || qstrcmp(s1,s2) == 0) // method has no args or return true; // exact match int s1len = qstrlen(s1); int s2len = qstrlen(s2); if (s2len < s1len && strncmp(s1,s2,s2len-1)==0 && s1[s2len-1]==',') return true; // method has less args return false;}static void qRemoveWhitespace(const char *s, char *d){ char last = 0; while (*s && is_space(*s)) s++; while (*s) { while (*s && !is_space(*s)) last = *d++ = *s++; while (*s && is_space(*s)) s++; if (*s && is_ident_char(*s) && is_ident_char(last)) last = *d++ = ' '; } *d = '\0';}static char *qNormalizeType(char *d, int &templdepth, QByteArray &result){ const char *t = d; while (*d && (templdepth || (*d != ',' && *d != ')'))) { if (*d == '<') ++templdepth; if (*d == '>') --templdepth; ++d; } if (strncmp("void", t, d - t) != 0) result += normalizeTypeInternal(t, d); return d;}/*! \since 4.2 Normalizes a \a type. See QMetaObject::normalizedSignature() for a description on how Qt normalizes. Example: \code QByteArray normType = QMetaObject::normalizedType(" int const *"); // normType is now "const int*" \endcode \sa normalizedSignature() */QByteArray QMetaObject::normalizedType(const char *type){ QByteArray result; if (!type || !*type) return result; QVarLengthArray<char> stackbuf(strlen(type)); qRemoveWhitespace(type, stackbuf.data()); int templdepth = 0; qNormalizeType(stackbuf.data(), templdepth, result); return result;}/*! Normalizes the signature of the given \a method. Qt uses normalized signatures to decide whether two given signals and slots are compatible. Normalization reduces whitespace to a minimum, moves 'const' to the front where appropriate, removes 'const' from value types and replaces const references with values. \sa checkConnectArgs(), normalizedType() */QByteArray QMetaObject::normalizedSignature(const char *method){ QByteArray result; if (!method || !*method) return result; int len = strlen(method); char stackbuf[64]; char *buf = (len >= 64 ? new char[len+1] : stackbuf); qRemoveWhitespace(method, buf); char *d = buf; result.reserve(len); int argdepth = 0; int templdepth = 0; while (*d) { if (argdepth == 1) d = qNormalizeType(d, templdepth, result); if (*d == '(') ++argdepth; if (*d == ')') --argdepth; result += *d++; } if (buf != stackbuf) delete [] buf; return result;}/*! Invokes the \a member (a signal or a slot name) on the object \a obj. Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match. The invocation can be either synchronous or asynchronous, depending on \a type: \list \o If \a type is Qt::DirectConnection, the member will be invoked immediately. \o If \a type is Qt::QueuedConnection, a QEvent will be sent and the member is invoked as soon as the application enters the main event loop. \o If \a type is Qt::AutoConnection, the member is invoked synchronously if \a obj lives in the same thread as the caller; otherwise it will invoke the member asynchronously. \endlist The return value of the \a member function call is placed in \a ret. If the invocation is asynchronous, the return value cannot be evaluated. You can pass up to ten arguments (\a val0, \a val1, \a val2, \a val3, \a val4, \a val5, \a val6, \a val7, \a val8, and \a val9) to the \a member function. QGenericArgument and QGenericReturnArgument are internal helper classes. Because signals and slots can be dynamically invoked, you must enclose the arguments using the Q_ARG() and Q_RETURN_ARG() macros. Q_ARG() takes a type name and a const reference of that type; Q_RETURN_ARG() takes a type name and a non-const reference. To asynchronously invoke the \l{QPushButton::animateClick()}{animateClick()} slot on a QPushButton: \code QMetaObject::invokeMethod(pushButton, "animateClick", Qt::QueuedConnection); \endcode With asynchronous method invocations, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message \code QMetaObject::invokeMethod: Unable to handle unregistered datatype 'MyType' \endcode call qRegisterMetaType() to register the data type before you call invokeMethod(). To synchronously invoke the \c compute(QString, int, double) slot on some arbitrary object \c obj retrieve its return value: \code QString retVal; QMetaObject::invokeMethod(obj, "compute", Qt::DirectConnection, Q_RETURN_ARG(QString, retVal), Q_ARG(QString, "sqrt"), Q_ARG(int, 42), Q_ARG(double, 9.7)); \endcode If the "compute" slot does not take exactly one QString, one int and one double in the specified order, the call will fail. \sa Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType()*/bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9){ if (!obj) return false; QVarLengthArray<char, 512> sig; int len = qstrlen(member); if (len <= 0) return false; sig.append(member, len); sig.append('('); enum { ParamCount = 11 }; const char *typeNames[] = {ret.name(), val0.name(), val1.name(), val2.name(), val3.name(), val4.name(), val5.name(), val6.name(), val7.name(), val8.name(), val9.name()}; int i; for (i = 1; i < ParamCount; ++i) { len = qstrlen(typeNames[i]); if (len <= 0) break; sig.append(typeNames[i], len); sig.append(','); } if (i == 1) sig.append(')'); // no parameters else sig[sig.size() - 1] = ')'; sig.append('\0'); int idx = obj->metaObject()->indexOfMethod(sig.constData()); if (idx < 0) { QByteArray norm = QMetaObject::normalizedSignature(sig.constData()); idx = obj->metaObject()->indexOfMethod(norm.constData()); } if (idx < 0) return false; // check return type if (ret.data()) { const char *retType = obj->metaObject()->method(idx).typeName(); if (qstrcmp(ret.name(), retType) != 0) { // normalize the return value as well // the trick here is to make a function signature out of the return type // so that we can call normalizedSignature() and avoid duplicating code QByteArray unnormalized; int len = qstrlen(ret.name()); unnormalized.reserve(len + 3); unnormalized = "_("; // the function is called "_" unnormalized.append(ret.name()); unnormalized.append(')'); QByteArray normalized = QMetaObject::normalizedSignature(unnormalized.constData()); normalized.truncate(normalized.length() - 1); // drop the ending ')' if (qstrcmp(normalized.constData() + 2, retType) != 0) return false; } } void *param[] = {ret.data(), val0.data(), val1.data(), val2.data(), val3.data(), val4.data(), val5.data(), val6.data(), val7.data(), val8.data(), val9.data()}; if (type == Qt::AutoConnection) { type = QThread::currentThread() == obj->thread() ? Qt::DirectConnection : Qt::QueuedConnection; } if (type != Qt::QueuedConnection) { return obj->qt_metacall(QMetaObject::InvokeMetaMethod, idx, param) < 0; } else { if (ret.data()) { qWarning("QMetaObject::invokeMethod: Unable to invoke methods with return values in queued " "connections"); return false; } int nargs = 1; // include return type void **args = (void **) qMalloc(ParamCount * sizeof(void *)); int *types = (int *) qMalloc(ParamCount * sizeof(int)); types[0] = 0; // return type args[0] = 0; for (i = 1; i < ParamCount; ++i) { types[i] = QMetaType::type(typeNames[i]); if (types[i]) { args[i] = QMetaType::construct(types[i], param[i]); ++nargs; } else if (param[i]) { qWarning("QMetaObject::invokeMethod: Unable to handle unregistered datatype '%s'", typeNames[i]); return false; } } QCoreApplication::postEvent(obj, new QMetaCallEvent(idx, 0, -1, -1, nargs, types, args)); } return true;}/*! \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, QGenericReturnArgument ret, QGenericArgument val0 = QGenericArgument(0), QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), QGenericArgument val4 = QGenericArgument(), QGenericArgument val5 = QGenericArgument(), QGenericArgument val6 = QGenericArgument(), QGenericArgument val7 = QGenericArgument(), QGenericArgument val8 = QGenericArgument(), QGenericArgument val9 = QGenericArgument()); \overload This overload always invokes the member using the connection type Qt::AutoConnection.*//*! \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericArgument val0 = QGenericArgument(0), QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), QGenericArgument val4 = QGenericArgument(), QGenericArgument val5 = QGenericArgument(), QGenericArgument val6 = QGenericArgument(), QGenericArgument val7 = QGenericArgument(), QGenericArgument val8 = QGenericArgument(),
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -