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 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 对于 QPair <int, int>. The first component of the pair is the timer ID; the second component is the interval.
另请参阅 registeredTimers ().
构造新事件分派程序采用给定 parent .
销毁事件分派程序。
[signal]
void
QAbstractEventDispatcher::
aboutToBlock
()
此信号被发射在事件循环调用可能阻塞的函数之前。
另请参阅 awake ().
[signal]
void
QAbstractEventDispatcher::
awake
()
此信号发射,在事件循环从可能阻塞的函数返回后。
另请参阅 wakeUp () 和 aboutToBlock ().
发送 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:
若 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.
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.
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
()
唤醒事件循环。
注意: 此函数是 thread-safe .
另请参阅 awake ().