?? qcoreapplication.cpp
字號:
} } } } 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(). 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; } QThreadData *data = QThreadData::current(); if (receiver && receiver->d_func()->threadData != data) { qWarning("QCoreApplication::sendPostedEvents: Cannot send " "posted events for objects in another thread"); return; } ++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 no one 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.#ifdef QT_NO_EXCEPTIONS QCoreApplication::sendEvent(r, e);#else try { QCoreApplication::sendEvent(r, e); } catch (...) { locker.relock(); delete e; // since we were interrupted, we need another pass to make sure we clean everything up data->canWait = false; // uglehack: copied from below --data->postEventList.recursion; if (!data->postEventList.recursion && !data->canWait && data->eventDispatcher) data->eventDispatcher->wakeUp(); throw; // rethrow }#endif 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*///#define PAUL_TESTINGvoid QCoreApplication::removePostedEvents(QObject *receiver){#ifdef PAUL_TESTING QThreadData *data = receiver ? receiver->d_func()->threadData : self->d_func()->threadData;#else if (!receiver) return; QThreadData *data = receiver->d_func()->threadData;#endif 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.#ifdef PAUL_TESTING if (receiver && !receiver->d_func()->postedEvents) return;#else if (!receiver->d_func()->postedEvents) return;#endif int n = data->postEventList.size(); int j = 0;#ifdef PAUL_TESTING if (!receiver) { for (int i = 0; i < n; ++i) { const QPostEvent &pe = data->postEventList.at(i); if (pe.event) { --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; } } data->postEventList.clear(); return; }#endif 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; QThreadData *data = QThreadData::current(); QMutexLocker locker(&data->postEventList.mutex); if (data->postEventList.size() == 0) {#if defined(QT_DEBUG) qDebug("QCoreApplication::removePostedEvent: Internal error: %p %d is posted", (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("QCoreApplication::removePostedEvent: 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 CodecForTr The encoding specified by QTextCodec::codecForTr() (Latin-1 if none has been set). \value UnicodeUTF8 UTF-8. \value DefaultCodec (Obsolete) Use CodecForTr instead. \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 translation file \a translationFile to the list of translation files to be used for translations. Multiple translation files can be installed. Translations are searched for in the last installed translation file on, back to the first installed translation 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 + -