QAbstractEventDispatcher 类提供管理 Qt 事件队列的接口。 更多...
头: | #include <QAbstractEventDispatcher> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
继承: | QObject |
struct | TimerInfo |
QAbstractEventDispatcher (QObject * parent = nullptr) | |
virtual | ~QAbstractEventDispatcher () |
bool | filterNativeEvent (const QByteArray & eventType , void * message , qintptr * result ) |
void | installNativeEventFilter (QAbstractNativeEventFilter * filterObj ) |
virtual void | interrupt () = 0 |
virtual bool | processEvents (QEventLoop::ProcessEventsFlags flags ) = 0 |
virtual void | registerSocketNotifier (QSocketNotifier * notifier ) = 0 |
int | registerTimer (qint64 interval , Qt::TimerType timerType , QObject * object ) |
virtual void | registerTimer (int timerId , qint64 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 | 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 * | 实例 (QThread * thread = nullptr) |
事件分派程序接收来自窗口系统及其它来源的事件。然后将它们发送给 QCoreApplication or QApplication 实例,用于处理和交付。QAbstractEventDispatcher 提供事件交付的细粒度控制。
对于事件处理的简单控制,请使用 QCoreApplication::processEvents ().
为更好地控制应用程序的事件循环,调用 实例 () 和调用返回 QAbstractEventDispatcher 对象的函数。若想要使用自己的 QAbstractEventDispatcher 实例或 QAbstractEventDispatcher 子类实例,必须安装它采用 QCoreApplication::setEventDispatcher () 或 QThread::setEventDispatcher () before 已安装默认事件分派程序。
启动 main 事件循环通过调用 QCoreApplication::exec (),和停止通过调用 QCoreApplication::exit ()。本地事件循环可以被创建使用 QEventLoop .
履行长时间操作的程序可以调用 processEvents () 采用按位 OR 组合各种 QEventLoop::ProcessEventsFlag 值去控制应该交付哪些事件。
QAbstractEventDispatcher 还允许集成外部事件循环与 Qt 事件循环。
另请参阅 QEventLoop , QCoreApplication ,和 QThread .
[explicit]
QAbstractEventDispatcher::
QAbstractEventDispatcher
(
QObject
*
parent
= nullptr)
构造新事件分派程序采用给定 parent .
[virtual noexcept]
QAbstractEventDispatcher::
~QAbstractEventDispatcher
()
销毁事件分派程序。
[signal]
void
QAbstractEventDispatcher::
aboutToBlock
()
此信号被发射在事件循环调用可能阻塞的函数之前。
另请参阅 awake ().
[signal]
void
QAbstractEventDispatcher::
awake
()
此信号发射,在事件循环从可能阻塞的函数返回后。
另请参阅 wakeUp () 和 aboutToBlock ().
发送
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 了解细节。
另请参阅 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 () 每当可能时。
另请参阅 QObject::installEventFilter ().
[static]
QAbstractEventDispatcher
*QAbstractEventDispatcher::
实例
(
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.
注意: 此函数不连续处理事件;它返回在处理所有可用事件之后。
[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
,
qint64
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 () 函数)。
另请参阅 installNativeEventFilter () 和 QAbstractNativeEventFilter .
[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
()
唤醒事件循环。
注意: 此函数是 thread-safe .
另请参阅 awake ().