QAbstractEventDispatcher 類

The QAbstractEventDispatcher class provides an interface to manage Qt's event queue. 更多...

頭: #include <QAbstractEventDispatcher>
繼承: QObject

公共類型

typedef EventFilter
typedef TimerInfo

公共函數

QAbstractEventDispatcher (QObject * parent = 0)
~QAbstractEventDispatcher ()
bool filterEvent (void * message )
virtual void flush () = 0
virtual bool hasPendingEvents () = 0
virtual void interrupt () = 0
virtual bool processEvents (QEventLoop::ProcessEventsFlags flags ) = 0
virtual void registerSocketNotifier (QSocketNotifier * notifier ) = 0
int registerTimer (int interval , QObject * object )
virtual void registerTimer (int timerId , int interval , QObject * object ) = 0
virtual QList<TimerInfo> registeredTimers (QObject * object ) const = 0
EventFilter setEventFilter (EventFilter filter )
virtual void unregisterSocketNotifier (QSocketNotifier * notifier ) = 0
virtual bool unregisterTimer (int timerId ) = 0
virtual bool unregisterTimers (QObject * object ) = 0
virtual void wakeUp () = 0

信號

void aboutToBlock ()
void awake ()

靜態公共成員

QAbstractEventDispatcher * instance (QThread * thread = 0)

額外繼承成員

詳細描述

The QAbstractEventDispatcher class provides an interface to manage Qt's event queue.

事件分派程序接收來自窗口係統及其它來源的事件。然後將它們發送給 QCoreApplication or QApplication instance for processing and delivery. QAbstractEventDispatcher provides fine-grained control over event delivery.

對於事件處理的簡單控製,請使用 QCoreApplication::processEvents ().

為更好地控製應用程序的事件循環,調用 instance () and call functions on the QAbstractEventDispatcher object that is returned. If you want to use your own instance of QAbstractEventDispatcher or of a QAbstractEventDispatcher subclass, you must create your instance before you create the QApplication 對象。

啓動 main 事件循環通過調用 QCoreApplication::exec (),和停止通過調用 QCoreApplication::exit ()。本地事件循環可以被創建使用 QEventLoop .

履行長時間操作的程序可以調用 processEvents () 采用按位 OR 組閤各種 QEventLoop::ProcessEventsFlag 值去控製應該交付哪些事件。

QAbstractEventDispatcher also allows the integration of an external event loop with the Qt event loop. For example, the Motif Extension includes a reimplementation of QAbstractEventDispatcher that merges Qt and Motif events together.

另請參閱 QEventLoop and QCoreApplication .

成員類型文檔編製

typedef QAbstractEventDispatcher:: EventFilter

Typedef for a function with the signature

bool myEventFilter(void *message);
					

Note that the type of the message is platform dependent. The following table shows the message 's type on Windows, Mac, X11 and BlackBerry. You can do a static cast to these types.

平颱 type
Windows MSG
X11 XEvent
Mac NSEvent
BlackBerry bps_event_t

另請參閱 setEventFilter () 和 filterEvent ().

typedef QAbstractEventDispatcher:: TimerInfo

typedef 對於 QPair <int, int>. The first component of the pair is the timer ID; the second component is the interval.

另請參閱 registeredTimers ().

成員函數文檔編製

QAbstractEventDispatcher:: QAbstractEventDispatcher ( QObject * parent = 0)

構造新事件分派程序采用給定 parent .

QAbstractEventDispatcher:: ~QAbstractEventDispatcher ()

銷毀事件分派程序。

[signal] void QAbstractEventDispatcher:: aboutToBlock ()

此信號發射,在事件循環調用可以阻塞的函數前。

另請參閱 awake ().

[signal] void QAbstractEventDispatcher:: awake ()

此信號發射,在事件循環從可能阻塞的函數返迴後。

另請參閱 wakeUp () 和 aboutToBlock ().

bool QAbstractEventDispatcher:: filterEvent ( void * message )

發送 message through the event filter that was set by setEventFilter (). If no event filter has been set, this function returns false; otherwise, this function returns the result of the event filter function.

子類化的 QAbstractEventDispatcher must call this function for all messages received from the system to ensure compatibility with any extensions that may be used in the application.

Note that the type of message is platform dependent. See QAbstractEventDispatcher::EventFilter 瞭解細節。

另請參閱 setEventFilter ().

[pure virtual] void QAbstractEventDispatcher:: flush ()

Flushes the event queue. This normally returns almost immediately. Does nothing on platforms other than X11.

[pure virtual] bool QAbstractEventDispatcher:: hasPendingEvents ()

Returns true if there is an event waiting; otherwise returns false.

[static] QAbstractEventDispatcher * QAbstractEventDispatcher:: instance ( QThread * thread = 0)

Returns a pointer to the event dispatcher object for the specified thread 。若 thread is zero, the current thread is used. If no event dispatcher exists for the specified thread, this function returns 0.

注意: If Qt is built without thread support, the thread argument is ignored.

[pure virtual] void QAbstractEventDispatcher:: interrupt ()

Interrupts event dispatching; i.e. the event dispatcher will return from processEvents () 盡快。

[pure virtual] bool QAbstractEventDispatcher:: processEvents ( QEventLoop::ProcessEventsFlags flags )

處理待決事件匹配 flags until there are no more events to process. Returns true if an event was processed; otherwise returns false.

此函數尤其有用,若有長時間運行操作且不允許用戶輸入想要展示其進度;即:通過使用 QEventLoop::ExcludeUserInputEvents 標誌。

QEventLoop::WaitForMoreEvents flag is set in flags , the behavior of this function is as follows:

  • 若事件可用,此函數在處理它們後返迴。
  • If no events are available, this function will wait until more are available and return after processing newly available events.

QEventLoop::WaitForMoreEvents flag is not set in flags , and no events are available, this function will return immediately.

注意: 此函數不連續處理事件;它返迴在處理所有可用事件之後。

另請參閱 hasPendingEvents ().

[pure virtual] void QAbstractEventDispatcher:: registerSocketNotifier ( QSocketNotifier * notifier )

注冊 notifier with the event loop. Subclasses must implement this method to tie a socket notifier into another event loop.

int QAbstractEventDispatcher:: registerTimer ( int interval , QObject * object )

Registers a timer with the specified interval 為給定 object .

[pure virtual] void QAbstractEventDispatcher:: registerTimer ( int timerId , int interval , QObject * object )

注冊計時器采用指定 timerId and interval 為給定 object .

[pure virtual] QList < TimerInfo > QAbstractEventDispatcher:: registeredTimers ( QObject * object ) const

返迴注冊計時器列錶為 object . The timer ID is the first member in each pair; the interval is the second.

EventFilter QAbstractEventDispatcher:: setEventFilter ( EventFilter filter )

Replaces the event filter function for this QAbstractEventDispatcher with filter and returns the replaced event filter function. Only the current event filter function is called. If you want to use both filter functions, save the replaced EventFilter in a place where yours can call it.

The event filter function set here is called for all messages taken from the system event loop before the event is dispatched to the respective target, including the messages not meant for Qt objects.

The event filter function should return true if the message should be filtered, (i.e. stopped). It should return false to allow processing the message to continue.

By default, no event filter function is set (i.e., this function returns a null EventFilter the first time it is called).

[pure virtual] void QAbstractEventDispatcher:: unregisterSocketNotifier ( QSocketNotifier * notifier )

Unregisters notifier from the event dispatcher. Subclasses must reimplement this method to tie a socket notifier into another event loop. Reimplementations must call the base implementation.

[pure virtual] bool QAbstractEventDispatcher:: unregisterTimer ( int timerId )

Unregisters the timer with the given timerId . Returns true if successful; otherwise returns false.

另請參閱 registerTimer () 和 unregisterTimers ().

[pure virtual] bool QAbstractEventDispatcher:: unregisterTimers ( QObject * object )

Unregisters all the timers associated with the given object . Returns true if all timers were successful removed; otherwise returns false.

另請參閱 unregisterTimer () 和 registeredTimers ().

[pure virtual] void QAbstractEventDispatcher:: wakeUp ()

喚醒事件循環。

注意: 此函數是 綫程安全 .

另請參閱 awake ().