⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmetaobject.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        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.    \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.indexOf("::");                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;}/*!    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 inline bool is_ident_char(char s){    return ((s >= 'a' && s <= 'z')            || (s >= 'A' && s <= 'Z')            || (s >= '0' && s <= '9')            || s == '_'       );}static inline bool is_space(char s){    return (s == ' ' || s == '\t');}// WARNING: a copy of this function is in moc.cppstatic QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope = false, bool adjustConst = true){    int len = e - t;    /*      Convert 'char const *' into 'const char *'. Start at index 1,      not 0, because 'const char *' is already OK.    */    QByteArray constbuf;    for (int i = 1; i < len; i++) {        if ( t[i] == 'c'             && strncmp(t + i + 1, "onst", 4) == 0             && (i + 5 >= len || !is_ident_char(t[i + 5]))             && !is_ident_char(t[i-1])            ) {            constbuf = QByteArray(t, len);            if (is_space(t[i-1]))                constbuf.remove(i-1, 6);            else                constbuf.remove(i, 5);            constbuf.prepend("const ");            t = constbuf.data();            e = constbuf.data() + constbuf.length();            break;        }        /*          We musn't convert 'char * const *' into 'const char **'          and we must beware of 'Bar<const Bla>'.        */        if (t[i] == '&' || t[i] == '*' ||t[i] == '<')            break;    }    if (adjustConst && e > t + 6 && strncmp("const ", t, 6) == 0) {        if (*(e-1) == '&') { // treat const reference as value            t += 6;            --e;        } else if (is_ident_char(*(e-1))) { // treat const value as value            t += 6;        }    }    QByteArray result;    result.reserve(len);    // some type substitutions for 'unsigned x'    if (strncmp("unsigned ", t, 9) == 0) {        if (strncmp("int", t+9, 3) == 0) {            t += 9+3;            result += "uint";        } else if (strncmp("long", t+9, 4) == 0                   // preserve '[unsigned] long int'                   && (strlen(t + 9 + 4) < 4                       || strncmp(t + 9 + 4, " int", 4) != 0                      )                   // preserve '[unsigned] long long'                   && (strlen(t + 9 + 4) < 5                       || strncmp(t + 9 + 4, " long", 5) != 0                      )                  ) {            t += 9+4;            result += "ulong";        }    }    while (t != e) {        char c = *t++;        if (fixScope && c == ':' && *t == ':' ) {            ++t;            c = *t++;            int i = result.size() - 1;            while (i >= 0 && is_ident_char(result.at(i)))                   --i;            result.resize(i + 1);        }        result += c;        if (c == '<') {            //template recursion            const char* tt = t;            int templdepth = 1;            while (t != e) {                c = *t++;                if (c == '<')                    ++templdepth;                if (c == '>')                    --templdepth;                if (templdepth == 0) {                    result += normalizeTypeInternal(tt, t-1, fixScope, false);                    result += c;                    if (*t == '>')                        result += ' '; // avoid >>                    break;                }            }        }    }    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() */QByteArray QMetaObject::normalizedSignature(const char *method){    const char *s = method;    if (!s || !*s)        return "";    int len = qstrlen(s);    char stackbuf[64];    char *buf = (len >= 64 ? new char[len+1] : stackbuf);    char *d = buf;    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';    d = buf;    QByteArray result;    result.reserve(len);    int argdepth = 0;    int templdepth = 0;    while (*d) {        if (argdepth == 1) {            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);        }        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)            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, nargs, types, args));    }    return true;}/*! \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member,                                       QGenericReturnArgument ret,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -