QAbstractEventDispatcher 類提供管理 Qt 事件隊列的接口。 更多...
| 頭: | #include <QAbstractEventDispatcher> |
| qmake: | QT += core |
| 繼承: | QObject |
| struct | TimerInfo |
| QAbstractEventDispatcher (QObject * parent = nullptr) | |
| virtual | ~QAbstractEventDispatcher () |
| bool | filterNativeEvent (const QByteArray & eventType , void * message , long * result ) |
| void | installNativeEventFilter (QAbstractNativeEventFilter * filterObj ) |
| virtual void | interrupt () = 0 |
| virtual bool | processEvents (QEventLoop::ProcessEventsFlags flags ) = 0 |
| virtual bool | registerEventNotifier (QWinEventNotifier * notifier ) = 0 |
| virtual void | registerSocketNotifier (QSocketNotifier * notifier ) = 0 |
| int | registerTimer (int interval , Qt::TimerType timerType , QObject * object ) |
| virtual void | registerTimer (int timerId , int interval , Qt::TimerType timerType , QObject * object ) = 0 |
| virtual QList<QAbstractEventDispatcher::TimerInfo> | registeredTimers (QObject * object ) const = 0 |
| virtual int | remainingTime (int timerId ) = 0 |
| void | removeNativeEventFilter (QAbstractNativeEventFilter * filter ) |
| virtual void | unregisterEventNotifier (QWinEventNotifier * notifier ) = 0 |
| 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 = nullptr) |
事件分派程序接收來自窗口係統及其它來源的事件。然後將它們發送給 QCoreApplication or QApplication 實例,用於處理和交付。QAbstractEventDispatcher 提供事件交付的細粒度控製。
對於事件處理的簡單控製,請使用 QCoreApplication::processEvents ().
為更好地控製應用程序的事件循環,調用 instance () 和調用返迴 QAbstractEventDispatcher 對象的函數。若想要使用自己的 QAbstractEventDispatcher 實例或 QAbstractEventDispatcher 子類實例,必須安裝它采用 QCoreApplication::setEventDispatcher () 或 QThread::setEventDispatcher () before 已安裝默認事件分派程序。
啓動 main 事件循環通過調用 QCoreApplication::exec (),和停止通過調用 QCoreApplication::exit ()。本地事件循環可以被創建使用 QEventLoop .
履行長時間操作的程序可以調用 processEvents () 采用按位 OR 組閤各種 QEventLoop::ProcessEventsFlag 值去控製應該交付哪些事件。
QAbstractEventDispatcher 還允許集成外部事件循環與 Qt 事件循環。
另請參閱 QEventLoop , QCoreApplication ,和 QThread .
構造新事件分派程序采用給定 parent .
[signal]
void
QAbstractEventDispatcher::
aboutToBlock
()
此信號發射,在事件循環調用可以阻塞的函數前。
另請參閱 awake ().
[signal]
void
QAbstractEventDispatcher::
awake
()
此信號發射,在事件循環從可能阻塞的函數返迴後。
另請參閱 wakeUp () 和 aboutToBlock ().
[虛擬]
QAbstractEventDispatcher::
~QAbstractEventDispatcher
()
銷毀事件分派程序。
發送
message
透過事件過濾器設置通過
installNativeEventFilter
()。此函數返迴
true
as soon as an event filter returns
true
, and false otherwise to indicate that the processing of the event should continue.
子類化的 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. The type of event eventType is specific to the platform plugin chosen at run-time, and can be used to cast message to the right type. The result pointer is only used on Windows, and corresponds to the LRESULT pointer.
Note that the type of message is platform dependent. See QAbstractNativeEventFilter 瞭解細節。
該函數在 Qt 5.0 引入。
另請參閱 installNativeEventFilter () 和 QAbstractNativeEventFilter::nativeEventFilter ().
安裝事件過濾器 filterObj 對於應用程序收到的所有本機事件。
事件過濾器 filterObj 接收事件憑藉其 nativeEventFilter() function, which is called for all events received by all threads.
The nativeEventFilter() function should return true if the event should be filtered, (in this case, stopped). It should return false to allow normal Qt processing to continue: the native event can then be translated into a QEvent 並處理通過標準 Qt event 過濾,如 QObject::installEventFilter ().
若安裝瞭多個事件過濾器,則首先激活最後安裝的過濾器。
注意: The filter function set here receives native messages, that is, MSG or XEvent structs.
為獲得最大可移植性,應始終試著使用 QEvent objects and QObject::installEventFilter () 每當可能時。
該函數在 Qt 5.0 引入。
另請參閱 QObject::installEventFilter ().
[static]
QAbstractEventDispatcher
*QAbstractEventDispatcher::
instance
(
QThread
*
thread
= nullptr)
Returns a pointer to the event dispatcher object for the specified
thread
。若
thread
is
nullptr
, the current thread is used. If no event dispatcher exists for the specified thread, this function returns
nullptr
.
注意: If Qt is built without thread support, the thread argument is ignored.
[pure virtual]
void
QAbstractEventDispatcher::
interrupt
()
Interrupts event dispatching. The event dispatcher will return from processEvents () 盡快。
[pure virtual]
bool
QAbstractEventDispatcher::
processEvents
(
QEventLoop::ProcessEventsFlags
flags
)
處理待決事件匹配
flags
直到沒有更多要處理事件為止。返迴
true
if an event was processed; otherwise returns
false
.
This function is especially useful if you have a long running operation, and want to show its progress without allowing user input by using the 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]
bool
QAbstractEventDispatcher::
registerEventNotifier
(
QWinEventNotifier
*
notifier
)
This pure virtual method exists on windows only and has to be reimplemented by a Windows specific event dispatcher implementation. notifier 是 QWinEventNotifier instance to be registered.
The method should return true if the registration of notifier was successful, otherwise false.
QWinEventNotifier calls this method in it's constructor and there should never be a need to call this method directly.
另請參閱 QWinEventNotifier and unregisterEventNotifier ().
[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 and timerType 為給定 object and returns the timer id.
[pure virtual]
void
QAbstractEventDispatcher::
registerTimer
(
int
timerId
,
int
interval
,
Qt::TimerType
timerType
,
QObject
*
object
)
注冊計時器采用指定 timerId , interval ,和 timerType 為給定 object .
[pure virtual]
QList
<
QAbstractEventDispatcher::TimerInfo
> QAbstractEventDispatcher::
registeredTimers
(
QObject
*
object
) const
返迴注冊計時器列錶為
object
。
TimerInfo
結構擁有
timerId
,
interval
,和
timerType
成員。
另請參閱 Qt::TimerType .
[pure virtual]
int
QAbstractEventDispatcher::
remainingTime
(
int
timerId
)
Returns the remaining time in milliseconds with the given timerId . If the timer is inactive, the returned value will be -1. If the timer is overdue, the returned value will be 0.
另請參閱 Qt::TimerType .
Removes the event filter filter 從此對象。忽略請求,若尚未安裝這種事件過濾器。
將自動移除此對象的所有事件過濾器,當此對象被銷毀時。
It is always safe to remove an event filter, even during event filter filter activation (that is, even from within the nativeEventFilter() 函數)。
該函數在 Qt 5.0 引入。
另請參閱 installNativeEventFilter () 和 QAbstractNativeEventFilter .
[pure virtual]
void
QAbstractEventDispatcher::
unregisterEventNotifier
(
QWinEventNotifier
*
notifier
)
This pure virtual method exists on windows only and has to be reimplemented by a Windows specific event dispatcher implementation. notifier 是 QWinEventNotifier instance to be unregistered.
QWinEventNotifier calls this method in it's destructor and there should never be a need to call this method directly.
另請參閱 QWinEventNotifier and registerEventNotifier ().
[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
。返迴
true
若成功;否則返迴
false
.
另請參閱 registerTimer () 和 unregisterTimers ().
[pure virtual]
bool
QAbstractEventDispatcher::
unregisterTimers
(
QObject
*
object
)
Unregisters all the timers associated with the given
object
。返迴
true
if all timers were successful removed; otherwise returns
false
.
另請參閱 unregisterTimer () 和 registeredTimers ().
[pure virtual]
void
QAbstractEventDispatcher::
wakeUp
()
喚醒事件循環。
注意: 此函數是 綫程安全 .
另請參閱 awake ().