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

📄 qobject.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    \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    \fn T qFindChild(const QObject *obj, const QString &name = QString(), T dummy = 0)    \relates QObject    \overload    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()*//*!    \internal    \fn QList<T> qFindChildren(const QObject *obj, const QString &name = QString(), T dummy = 0)    \relates QObject    \overload    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()*//*!    \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;    for (i = 0; i < children.size(); ++i) {        obj = children.at(i);        if (mo.cast(obj) && (name.isNull() || obj->objectName() == name))            return obj;    }    for (i = 0; i < children.size(); ++i) {        obj = qt_qFindChild_helper(children.at(i), name, mo);        if (obj)            return obj;    }    return 0;}/*!    Makes the object a child of \a parent.    \sa QWidget::setParent()*/void QObject::setParent(QObject *parent){    Q_D(QObject);    Q_ASSERT(!d->isWidget);    d->setParent_helper(parent);}void QObjectPrivate::deleteChildren(){    const bool reallyWasDeleted = wasDeleted;    wasDeleted = true;    // delete children objects    // don't use qDeleteAll as the destructor of the child might    // delete siblings    for (int i = 0; i < children.count(); ++i) {        currentChildBeingDeleted = children.at(i);        children[i] = 0;        delete currentChildBeingDeleted;    }    children.clear();    currentChildBeingDeleted = 0;    wasDeleted = reallyWasDeleted;}void QObjectPrivate::setParent_helper(QObject *o){    Q_Q(QObject);    if (o == parent)        return;    if (parent) {        QObjectPrivate *parentD = parent->d_func();        if (parentD->wasDeleted && wasDeleted            && parentD->currentChildBeingDeleted == q) {            // don't do anything since QObjectPrivate::deleteChildren() already            // cleared our entry in parentD->children.        } else {            const int index = parentD->children.indexOf(q);            if (parentD->wasDeleted) {                parentD->children[index] = 0;            } else {                parentD->children.removeAt(index);                if (sendChildEvents && parentD->receiveChildEvents) {                    QChildEvent e(QEvent::ChildRemoved, q);                    QCoreApplication::sendEvent(parent, &e);                }            }        }    }    parent = o;    if (parent) {        // object hierarchies are constrained to a single thread        if (threadData != parent->d_func()->threadData) {            qWarning("QObject::setParent: New parent must be in the same thread as the previous parent");            parent = 0;            return;        }        parent->d_func()->children.append(q);        if(sendChildEvents && parent->d_func()->receiveChildEvents) {            if (!isWidget) {                QChildEvent e(QEvent::ChildAdded, q);                QCoreApplication::sendEvent(parent, &e);#ifdef QT3_SUPPORT                QCoreApplication::postEvent(parent, new QChildEvent(QEvent::ChildInserted, q));#endif            }        }    }}/*!    \fn void QObject::installEventFilter(QObject *filterObj)    \threadsafe    Installs an event filter \a filterObj on this object. For example:    \code    monitoredObj->installEventFilter(filterObj);    \endcode    An event filter is an object that receives all events that are    sent to this object. The filter can either stop the event or    forward it to this object. The event filter \a filterObj receives    events via its eventFilter() function. The eventFilter() function    must return true if the event should be filtered, (i.e. stopped);    otherwise it must return false.    If multiple event filters are installed on a single object, the    filter that was installed last is activated first.    Here's a \c KeyPressEater class that eats the key presses of its    monitored objects:    \code        class KeyPressEater : public QObject        {            Q_OBJECT            ...        protected:            bool eventFilter(QObject *obj, QEvent *event);        };        bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)        {            if (event->type() == QEvent::KeyPress) {                QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);                qDebug("Ate key press %d", keyEvent->key());                return true;            } else {                // standard event processing                return QObject::eventFilter(obj, event);            }        }    \endcode    And here's how to install it on two widgets:    \code        KeyPressEater *keyPressEater = new KeyPressEater(this);        QPushButton *pushButton = new QPushButton(this);        QListView *listView = new QListView(this);        pushButton->installEventFilter(keyPressEater);        listView->installEventFilter(keyPressEater);    \endcode    The QShortcut class, for example, uses this technique to intercept    shortcut key presses.    \warning If you delete the receiver object in your eventFilter()    function, be sure to return true. If you return false, Qt sends    the event to the deleted object and the program will crash.    \sa removeEventFilter(), eventFilter(), event()*/void QObject::installEventFilter(QObject *obj){    Q_D(QObject);    if (!obj)        return;    QWriteLocker locker(QObjectPrivate::readWriteLock());    // clean up unused items in the list    d->eventFilters.removeAll((QObject*)0);    d->eventFilters.removeAll(obj);    d->eventFilters.prepend(obj);}/*!    \threadsafe    Removes an event filter object \a obj from this object. The    request is ignored if such an event filter has not been installed.    All event filters for this object are automatically removed when    this object is destroyed.    It is always safe to remove an event filter, even during event    filter activation (i.e. from the eventFilter() function).    \sa installEventFilter(), eventFilter(), event()*/void QObject::removeEventFilter(QObject *obj){    Q_D(QObject);    QWriteLocker locker(QObjectPrivate::readWriteLock());    d->eventFilters.removeAll(obj);}/*!    \fn QObject::destroyed(QObject *obj)    This signal is emitted immediately before the object \a obj is    destroyed, and can not be blocked.    All the objects's children are destroyed immediately after this    signal is emitted.    \sa deleteLater(), QPointer*//*!    Schedules this object for deletion.    The object will be deleted when control returns to the event loop.    Note that entering and leaving a new event loop (e.g., by opening a modal    dialog) will \e not perform the deferred deletion; for the object to be    deleted, the control must return to the event loop from which    deleteLater() was called.    \bold{Note:} It is safe to call this function more than once; when the    first deferred deletion event is delivered, any pending events for the    object are removed from the event queue.    \sa destroyed(), QPointer*/void QObject::deleteLater(){    QCoreApplication::postEvent(this, new QEvent(QEvent::DeferredDelete));}/*!    \fn QString QObject::tr(const char *sourceText, const char *comment, int n)    \reentrant    Returns a translated version of \a sourceText, or \a sourceText    itself if there is no appropriate translated version. The    translation context is Object with \a comment (0 by default).    All QObject subclasses using the Q_OBJECT macro automatically have    a reimplementation of this function with the subclass name as    context.    You can set the encoding for \a sourceText by calling QTextCodec::setCodecForTr().    By default \a sourceText is assumed to be in Latin-1 encoding.    Example:    \code        MyWindow::MyWindow()        {            QLabel *nameLabel = new QLabel(tr("Name:"));            QLabel *addressLabel = new QLabel(tr("Address:", "i.e. a postal address"));            ...        }    \endcode    If \a n >= 0, all occurrences of \c %n in the resulting string    are replaced with a decimal representation of \a n. In addition,    depending on \a n's value, the translation text may vary.    Example:    \code        int n = messages.count();        showMessage(tr("%n message(s) saved", "", n));    \endcode    The table below shows what string is returned depending on the    active translation:    \table    \header \o      \o{3,1} Active Translation    \header \o \a n \o No Translation        \o French                                 \o English    \row    \o 0    \o "0 message(s) saved"  \o "0 message sauvegard\unicode{0xE9}"    \o "0 message\bold{s} saved"    \row    \o 1    \o "1 message(s) saved"  \o "1 message sauvegard\unicode{0xE9}"    \o "1 message saved"    \row    \o 2    \o "2 message(s) saved"  \o "2 message\bold{s} sauvegard\unicode{0xE9}\bold{s}"  \o "2 message\bold{s} saved"    \row    \o 37   \o "37 message(s) saved" \o "37 message\bold{s} sauvegard\unicode{0xE9}\bold{s}" \o "37 message\bold{s} saved"    \endtable    This idiom is more flexible than the traditional approach, i.e.,    \code        n == 1 ? tr("%n message saved") : tr("%n messages saved")    \endcode    because it also works with target languages that have several    plural forms (e.g., Irish has a special "dual" form that should    be used when \c n is 2), and it handles the \e n == 0 case    correctly for languages such as French that require the singular.    See the \l{Qt Linguist Manual} for details.    Instead of \c %n, you can use \c %Ln to produce a localized    representation of \a n. The conversion uses the default local,    set using QLocal::setDefault(). (If no default locale was    specified, the "C" locale is used.)    \warning This method is reentrant only if all translators are    installed \e before calling this method. Installing or removin

⌨️ 快捷键说明

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