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

📄 qcoreapplication.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#ifdef QT3_SUPPORT        if (event->type() == QEvent::ChildInserted)            ++receiver->d_func()->postedChildInsertedEvents;#endif        if (event->type() == QEvent::DeferredDelete) {            if (!data->eventLoops.isEmpty()) {                // remember the current running eventloop                for (int i = data->eventLoops.size() - 1; i >= 0; --i) {                    QEventLoop *eventLoop = data->eventLoops.at(i);                    if (eventLoop->isRunning()) {                        event->d = reinterpret_cast<QEventPrivate *>(eventLoop);                        break;                    }                }            }        }        data->postEventList.append(QPostEvent(receiver, event));        data->canWait = false;    }    if (data->eventDispatcher)        data->eventDispatcher->wakeUp();}/*!  \internal  Returns true if \a event should be blocked and deleted*/bool QCoreApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents){#ifdef Q_WS_WIN    Q_ASSERT(event);    Q_ASSERT(receiver);    Q_ASSERT(postedEvents);    // compress posted timers to this object.    if (event->type() == QEvent::Timer && receiver->d_func()->postedEvents > 0) {        int timerId = ((QTimerEvent *) event)->timerId();        for (int i=0; i<postedEvents->size(); ++i) {            const QPostEvent &e = postedEvents->at(i);            if (e.receiver == receiver && e.event && e.event->type() == QEvent::Timer                && ((QTimerEvent *) e.event)->timerId() == timerId)                return true;        }    }#else    Q_UNUSED(event);    Q_UNUSED(receiver);    Q_UNUSED(postedEvents);#endif    return false;}/*!  \fn void QCoreApplication::sendPostedEvents()  \overload    Dispatches all posted events, i.e. empties the event queue.*//*!  Immediately dispatches all events which have been previously queued  with QCoreApplication::postEvent() and which are for the object \a receiver  and have the event type \a event_type.  Note that events from the window system are \e not dispatched by this  function, but by processEvents().  If \a receiver is null, the events of \a event_type are sent for all  objects. If \a event_type is 0, all the events are sent for \a receiver.  \sa flush(), postEvent()*/void QCoreApplication::sendPostedEvents(QObject *receiver, int event_type){    bool doDeferredDeletion = (event_type == QEvent::DeferredDelete);    if (event_type == -1) {        // we were called by the event dispatcher.        doDeferredDeletion = true;        event_type = 0;    }    QThread *currentThread = QThread::currentThread();    if (self) {        // allow sendPostedEvents() to be called when QCoreApplication        // is not instantiated        Q_ASSERT_X(currentThread != 0, "QCoreApplication::sendPostedEvents",                   "Posted events can only be send from threads started with QThread");        if (!currentThread)            return;    }    if (receiver) {        QThread *thr = receiver->thread();        Q_ASSERT_X(thr == currentThread || !thr, "QCoreApplication::sendPostedEvents",                   "Cannot send posted events for object created in another thread");        if (thr == 0 || thr != currentThread)            return;    }    QThreadData *data = QThreadData::get(currentThread);    ++data->postEventList.recursion;#ifdef QT3_SUPPORT    // optimize sendPostedEvents(w, QEvent::ChildInserted) calls away    if (receiver && event_type == QEvent::ChildInserted        && !receiver->d_func()->postedChildInsertedEvents) {        --data->postEventList.recursion;        return;    }    // Make sure the object hierarchy is stable before processing events    // to avoid endless loops    if (receiver == 0 && event_type == 0)        sendPostedEvents(0, QEvent::ChildInserted);#endif    QMutexLocker locker(&data->postEventList.mutex);    // by default, we assume that the event dispatcher can go to sleep after    // processing all events. if any new events are posted while we send    // events, canWait will be set to false.    data->canWait = (data->postEventList.size() == 0);    if (data->postEventList.size() == 0 || (receiver && !receiver->d_func()->postedEvents)) {        --data->postEventList.recursion;        return;    }    data->canWait = true;    // okay. here is the tricky loop. be careful about optimizing    // this, it looks the way it does for good reasons.    int i = 0;    const int s = data->postEventList.size();    while (i < data->postEventList.size()) {        // avoid live-lock        if (i >= s)            break;        const QPostEvent &pe = data->postEventList.at(i);        ++i;        if (!pe.event)            continue;        if ((receiver && receiver != pe.receiver) || (event_type && event_type != pe.event->type())) {            data->canWait = false;            continue;        }        if (pe.event->type() == QEvent::DeferredDelete) {            const QEventLoop *const savedEventLoop = reinterpret_cast<QEventLoop *>(pe.event->d);            const QEventLoop *const currentEventLoop =                data->eventLoops.isEmpty() ? 0 : data->eventLoops.top();            // DeferredDelete events are only sent when we are explicitly            // asked to (s.a. QEventLoop::DeferredDeletion), and then only if            // there is no current event loop, or if the current event loop is            // equal to the loop in which deleteLater() was called.            if (!doDeferredDeletion || (currentEventLoop && savedEventLoop && savedEventLoop != currentEventLoop)) {                // cannot send deferred delete                if (!event_type && !receiver) {                    // don't lose the event                    data->postEventList.append(pe);                    const_cast<QPostEvent &>(pe).event = 0;                }                continue;            }        }        // first, we diddle the event so that we can deliver        // it, and that noone will try to touch it later.        pe.event->posted = false;        QEvent * e = pe.event;        QObject * r = pe.receiver;        --r->d_func()->postedEvents;        Q_ASSERT(r->d_func()->postedEvents >= 0);#ifdef QT3_SUPPORT        if (e->type() == QEvent::ChildInserted)            --r->d_func()->postedChildInsertedEvents;        Q_ASSERT(r->d_func()->postedChildInsertedEvents >= 0);#endif        // next, update the data structure so that we're ready        // for the next event.        const_cast<QPostEvent &>(pe).event = 0;        locker.unlock();        // after all that work, it's time to deliver the event.        QCoreApplication::sendEvent(r, e);        locker.relock();        delete e;        // careful when adding anything below this point - the        // sendEvent() call might invalidate any invariants this        // function depends on.    }    --data->postEventList.recursion;    if (!data->postEventList.recursion && !data->canWait && data->eventDispatcher)        data->eventDispatcher->wakeUp();    // clear the global list, i.e. remove everything that was    // delivered.    if (!data->postEventList.recursion && !event_type && !receiver) {        const QPostEventList::iterator it = data->postEventList.begin();        data->postEventList.erase(it, it + i);    }}/*!  Removes all events posted using postEvent() for \a receiver.  The events are \e not dispatched, instead they are removed from the  queue. You should never need to call this function. If you do call it,  be aware that killing events may cause \a receiver to break one or  more invariants.  \threadsafe*/void QCoreApplication::removePostedEvents(QObject *receiver){    if (!receiver)        return;    QThread *thr = receiver->thread();    if (!thr)        thr = mainThread();    if (!thr)        return;    QThreadData *data = QThreadData::get(thr);    QMutexLocker locker(&data->postEventList.mutex);    // the QObject destructor calls this function directly.  this can    // happen while the event loop is in the middle of posting events,    // and when we get here, we may not have any more posted events    // for this object.    if (!receiver->d_func()->postedEvents) return;    int n = data->postEventList.size();    int j = 0;    for (int i = 0; i < n; ++i) {        const QPostEvent &pe = data->postEventList.at(i);        if (pe.receiver == receiver) {            if (pe.event) {                --receiver->d_func()->postedEvents;#ifdef QT3_SUPPORT                if (pe.event->type() == QEvent::ChildInserted)                    --receiver->d_func()->postedChildInsertedEvents;#endif                pe.event->posted = false;                delete pe.event;                const_cast<QPostEvent &>(pe).event = 0;            }        } else if (!data->postEventList.recursion) {            if (i != j)                data->postEventList.swap(i, j);            ++j;        }    }    Q_ASSERT(!receiver->d_func()->postedEvents);#ifdef QT3_SUPPORT    Q_ASSERT(!receiver->d_func()->postedChildInsertedEvents);#endif    if (!data->postEventList.recursion) {        while (j++ < n)            data->postEventList.removeLast();    }}/*!  Removes \a event from the queue of posted events, and emits a  warning message if appropriate.  \warning This function can be \e really slow. Avoid using it, if  possible.  \threadsafe*/void QCoreApplicationPrivate::removePostedEvent(QEvent * event){    if (!event || !event->posted)        return;    QThread *thread = QThread::currentThread();    if (!thread)        return;    QThreadData *data = QThreadData::get(thread);    QMutexLocker locker(&data->postEventList.mutex);    if (data->postEventList.size() == 0) {#if defined(QT_DEBUG)        qDebug("QCoreApplication::removePostedEvent: %p %d is posted: impossible",                (void*)event, event->type());        return;#endif    }    for (int i = 0; i < data->postEventList.size(); ++i) {        const QPostEvent & pe = data->postEventList.at(i);        if (pe.event == event) {#ifndef QT_NO_DEBUG            qWarning("QEvent: Warning: event of type %d deleted while posted to %s %s",                     event->type(),                     pe.receiver->metaObject()->className(),                     pe.receiver->objectName().toLocal8Bit().data());#endif            --pe.receiver->d_func()->postedEvents;#ifdef QT3_SUPPORT            if (pe.event->type() == QEvent::ChildInserted)                --pe.receiver->d_func()->postedChildInsertedEvents;#endif            pe.event->posted = false;            delete pe.event;            const_cast<QPostEvent &>(pe).event = 0;            return;        }    }}/*!\reimp*/bool QCoreApplication::event(QEvent *e){    if (e->type() == QEvent::Quit) {        quit();        return true;    }    return QObject::event(e);}/*! \enum QCoreApplication::Encoding  This enum type defines the 8-bit encoding of character string  arguments to translate():  \value DefaultCodec  The encoding specified by  QTextCodec::codecForTr() (Latin1 if none has been set)  \value UnicodeUTF8  UTF-8  \sa QObject::tr(), QObject::trUtf8(), QString::fromUtf8()*//*!    Tells the application to exit with return code 0 (success).    Equivalent to calling QCoreApplication::exit(0).    It's common to connect the QApplication::lastWindowClosed() signal    to quit(), and you also often connect e.g. QAbstractButton::clicked() or    signals in QAction, QMenu, or QMenuBar to it.    Example:    \code        QPushButton *quitButton = new QPushButton("Quit");        connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));    \endcode    \sa exit(), aboutToQuit(), QApplication::lastWindowClosed()*/void QCoreApplication::quit(){    exit(0);}/*!  \fn void QCoreApplication::aboutToQuit()  This signal is emitted when the application is about to quit the  main event loop, e.g. when the event loop level drops to zero.  This may happen either after a call to quit() from inside the  application or when the users shuts down the entire desktop session.  The signal is particularly useful if your application has to do some  last-second cleanup. Note that no user interaction is possible in  this state.  \sa quit()*/#ifndef QT_NO_TRANSLATION/*!  Adds the message file \a messageFile to the list of message files to be used  for translations.  Multiple message files can be installed. Translations are searched  for in the last installed message file, then the one from last, and  so on, back to the first installed message file. The search stops as  soon as a matching translation is found.  \sa removeTranslator() translate() QTranslator::load()

⌨️ 快捷键说明

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