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

📄 qobject.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    }    // set new thread id    thread = newThreadId;    for (int i = 0; i < children.size(); ++i) {        QObject *child = children.at(i);        child->d_func()->setThreadId_helper(currentData, targetData, newThreadId);    }}void QObjectPrivate::_q_reregisterTimers(void *pointer){    Q_Q(QObject);    QThread *objectThread = q->thread();    QList<QPair<int, int> > *timerList =        reinterpret_cast<QList<QPair<int, int> > *>(pointer);    if (objectThread) {        QThreadData *threadData = QThreadData::get(objectThread);        QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher;        for (int i = 0; i < timerList->size(); ++i) {            const QPair<int, int> &pair = timerList->at(i);            eventDispatcher->registerTimer(pair.first, pair.second, q);        }    }    delete timerList;}//// The timer flag hasTimer is set when startTimer is called.// It is not reset when killing the timer because more than// one timer might be active.///*!    Starts a timer and returns a timer identifier, or returns zero if    it could not start a timer.    A timer event will occur every \a interval milliseconds until    killTimer() is called. If \a interval is 0, then the timer event    occurs once every time there are no more window system events to    process.    The virtual timerEvent() function is called with the QTimerEvent    event parameter class when a timer event occurs. Reimplement this    function to get timer events.    If multiple timers are running, the QTimerEvent::timerId() can be    used to find out which timer was activated.    Example:    \code        class MyObject : public QObject        {            Q_OBJECT        public:            MyObject(QObject *parent = 0);        protected:            void timerEvent(QTimerEvent *event);        };        MyObject::MyObject(QObject *parent)            : QObject(parent)        {            startTimer(50);     // 50-millisecond timer            startTimer(1000);   // 1-second timer            startTimer(60000);  // 1-minute timer        }        void MyObject::timerEvent(QTimerEvent *event)        {            qDebug() << "Timer ID:" << event->timerId();        }    \endcode    Note that QTimer's accuracy depends on the underlying operating    system and hardware. Most platforms support an accuracy of 20    milliseconds; some provide more. If Qt is unable to deliver the    requested number of timer events, it will silently discard some.    The QTimer class provides a high-level programming interface with    single-shot timers and timer signals instead of events. There is    also a QBasicTimer class that is more lightweight than QTimer and    less clumsy than using timer IDs directly.    \sa timerEvent(), killTimer(), QTimer::singleShot()*/int QObject::startTimer(int interval){    Q_D(QObject);    QThread *thr = thread();    if (!thr && d->thread != 0) {        qWarning("QTimer can only be used with a valid thread");        return 0;    }    if (interval < 0) {        qWarning("QTimer cannot have a negative interval");        return 0;    }    d->pendTimer = true;                                // set timer flag    QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(thr);    if (!eventDispatcher) {        qWarning("QTimer can only be used with threads started with QThread");        return 0;    }    return eventDispatcher->registerTimer(interval, this);}/*!    Kills the timer with timer identifier, \a id.    The timer identifier is returned by startTimer() when a timer    event is started.    \sa timerEvent(), startTimer()*/void QObject::killTimer(int id){    Q_D(QObject);    QThread *thr = thread();    if (!thr && d->thread != 0) {        qWarning("QTimer can only be used with a valid thread");        return;    }    QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(thread());    if (eventDispatcher)        eventDispatcher->unregisterTimer(id);}/*!    \fn QObject *QObject::parent() const    Returns a pointer to the parent object.    \sa children()*//*!    \fn const QObjectList &QObject::children() const    Returns a list of child objects.    The QObjectList class is defined in the \c{<QObject>} header    file as the following:    \quotefromfile src/corelib/kernel/qobject.h    \skipto /typedef .*QObjectList/    \printuntil QObjectList    The first child added is the \l{QList::first()}{first} object in    the list and the last child added is the \l{QList::last()}{last}    object in the list, i.e. new children are appended at the end.    Note that the list order changes when QWidget children are    \l{QWidget::raise()}{raised} or \l{QWidget::lower()}{lowered}. A    widget that is raised becomes the last object in the list, and a    widget that is lowered becomes the first object in the list.    \sa findChild(), findChildren(), parent(), setParent()*/#ifdef QT3_SUPPORTstatic void objSearch(QObjectList &result,                       const QObjectList &list,                       const char  *inheritsClass,                       bool onlyWidgets,                       const char  *objName,                       QRegExp           *rx,                       bool            recurse){    for (int i = 0; i < list.size(); ++i) {        QObject *obj = list.at(i);        bool ok = true;        if (onlyWidgets)            ok = obj->isWidgetType();        else if (inheritsClass && !obj->inherits(inheritsClass))            ok = false;        if (ok) {            if (objName)                ok = (obj->objectName() == QLatin1String(objName));#ifndef QT_NO_REGEXP            else if (rx)                ok = (rx->indexIn(obj->objectName()) != -1);#endif        }        if (ok)                                // match!            result.append(obj);        if (recurse) {            QObjectList clist = obj->children();            if (!clist.isEmpty())                objSearch(result, clist, inheritsClass,                           onlyWidgets, objName, rx, recurse);        }    }}/*!    \internal    Searches the children and optionally grandchildren of this object,    and returns a list of those objects that are named or that match    \a objName and inherit \a inheritsClass. If \a inheritsClass is 0    (the default), all classes match. If \a objName is 0 (the    default), all object names match.    If \a regexpMatch is true (the default), \a objName is a regular    expression that the objects's names must match. The syntax is that    of a QRegExp. If \a regexpMatch is false, \a objName is a string    and object names must match it exactly.    Note that \a inheritsClass uses single inheritance from QObject,    the way inherits() does. According to inherits(), QWidget    inherits QObject but not QPaintDevice. This does not quite match    reality, but is the best that can be done on the wide variety of    compilers Qt supports.    Finally, if \a recursiveSearch is true (the default), queryList()    searches \e{n}th-generation as well as first-generation children.    If all this seems a bit complex for your needs, the simpler    child() function may be what you want.    This somewhat contrived example disables all the buttons in this    window:    \code        QList<QObject *> list = window()->queryList("QAbstractButton"));        foreach (QObject *obj, list)            static_cast<QAbstractButton *>(obj)->setEnabled(false);    \endcode    \warning Delete the list as soon you have finished using it. The    list contains pointers that may become invalid at almost any time    without notice (as soon as the user closes a window you may have    dangling pointers, for example).    \sa child() children(), parent(), inherits(), objectName(), QRegExp*/QObjectList QObject::queryList(const char *inheritsClass,                                const char *objName,                                bool regexpMatch,                                bool recursiveSearch) const{    Q_D(const QObject);    QObjectList list;    bool onlyWidgets = (inheritsClass && qstrcmp(inheritsClass, "QWidget") == 0);#ifndef QT_NO_REGEXP    if (regexpMatch && objName) {                // regexp matching        QRegExp rx(QString::fromLatin1(objName));        objSearch(list, d->children, inheritsClass, onlyWidgets, 0, &rx, recursiveSearch);    } else#endif    {        objSearch(list, d->children, inheritsClass, onlyWidgets, objName, 0, recursiveSearch);    }    return list;}#endif/*!    \fn T *QObject::findChild(const QString &name) const    Returns the child of this object that can be casted into type T and    that is called \a name, or 0 if there is no such object.    An empty string matches all object names.    The search is performed recursively.    If there is more than one child matching the search, the most    direct ancestor is returned. If there are several direct    ancestors, it is undefined which one will be returned. In that    case, findChildren() should be used.    This example returns a child \l{QPushButton} of \c{parentWidget}    named \c{"button1"}:    \code        QPushButton *button = parentWidget->findChild<QPushButton *>("button1");    \endcode    This example returns a \l{QListWidget} child of \c{parentWidget}:    \code        QListWidget *list = parentWidget->findChild<QListWidget *>();    \endcode    \warning This function is not available with MSVC 6. Use    qFindChild() instead if you need to support that version of the    compiler.    \sa findChildren(), qFindChild()*//*!    \fn QList<T> QObject::findChildren(const QString &name) const    Returns all children of this object with the given \a name that can be    cast to type T, or an empty list if there are no such objects.    An empty string matches all object names.    The search is performed recursively.    The following example shows how to find a list of child \l{QWidget}s of    the specified \c{parentWidget} named \c{widgetname}:    \code        QList<QWidget *> widgets = parentWidget.findChildren<QWidget *>("widgetname");    \endcode    This example returns all \c{QPushButton}s that are children of \c{parentWidget}:    \code        QList<QPushButton *> allPButtons = parentWidget.findChildren<QPushButton *>();    \endcode    \warning This function is not available with MSVC 6. Use    qFindChildren() instead if you need to support that version of the    compiler.    \sa findChild(), qFindChildren()*//*!    \fn QList<T> QObject::findChildren(const QRegExp &regExp) const    \overload    Returns the children of this object that can be casted to type T    and that have names matching the regular expression \a regExp,    or an empty list if there are no such objects.    The search is performed recursively.    \warning This function is not available with MSVC 6. Use    qFindChildren() instead if you need to support that version of the    compiler.*//*!    \fn T qFindChild(const QObject *obj, const QString &name)    \relates QObject    This function is equivalent to    \a{obj}->\l{QObject::findChild()}{findChild}<T>(\a name). It is    provided as a work-around for MSVC 6, which doesn't support    member template functions.    \sa QObject::findChild()*//*!    \fn QList<T> qFindChildren(const QObject *obj, const QString &name)    \relates QObject    This function is equivalent to    \a{obj}->\l{QObject::findChildren()}{findChildren}<T>(\a name). It is    provided as a work-around for MSVC 6, which doesn't support    member template functions.    \sa QObject::findChildren()*//*!    \fn QList<T> qFindChildren(const QObject *obj, const QRegExp &regExp)    \relates QObject    \overload    This function is equivalent to    \a{obj}->\l{QObject::findChildren()}{findChildren}<T>(\a regExp). It is    provided as a work-around for MSVC 6, which doesn't support    member template functions.*//*!    \internal*/void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QRegExp *re,                         const QMetaObject &mo, QList<void*> *list){    if (!parent || !list)        return;    const QObjectList &children = parent->children();    QObject *obj;    for (int i = 0; i < children.size(); ++i) {        obj = children.at(i);        if (mo.cast(obj)) {            if (re) {                if (re->indexIn(obj->objectName()) != -1)                    list->append(obj);            } else {                if (name.isNull() || obj->objectName() == name)                    list->append(obj);            }        }        qt_qFindChildren_helper(obj, name, re, mo, list);    }}/*! \internal */QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo){    if (!parent)        return 0;    const QObjectList &children = parent->children();    QObject *obj;    int i;

⌨️ 快捷键说明

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