QAbstractEventDispatcher Class
QAbstractEventDispatcher 提供了管理 Qt 事件队列的接口. 更多...
头文件: | #include <QAbstractEventDispatcher> |
qmake: | QT += core |
基类: | QObject |
公有类型
class | TimerInfo |
公有函数
QAbstractEventDispatcher(QObject *parent = Q_NULLPTR) | |
~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<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 |
- 32 个公有函数继承自 QObject
信号
void | aboutToBlock() |
void | awake() |
- 2 个信号继承自 QObject
静态公有成员
QAbstractEventDispatcher * | instance(QThread *thread = Q_NULLPTR) |
- 11 个静态公有成员继承自 QObject
其他继承的成员
详细描述
QAbstractEventDispatcher 提供了管理 Qt 事件队列的接口.
事件调度程序从窗口系统和其他源接收事件. 然后, 它将它们发送到 QCoreApplication 或 QApplication 实例处理或交付. QAbstractEventDispatcher 提供对事件传递的细粒度控制.
想要简单地控制事件处理, 使用 QCoreApplication::processEvents().
为了更好地控制应用程序的事件循环, 调用 instance() 获取 QAbstractEventDispatcher 对象, 然后再调用它的函数. 如果你想使用自己的 QAbstractEventDispatcher 实例或 QAbstractEventDispatcher 子类实例, 你必须在安装默认事件调度程序之前, 调用 QCoreApplication::setEventDispatcher() 或 QThread::setEventDispatcher() 安装它.
主事件循环调用 QCoreApplication::exec() 启动, 调用 QCoreApplication::exit() 停止. 本地事件循环可以使用 QEventLoop 创建.
执行长操作的程序可以使用 QEventLoop::ProcessEventsFlag 值的按位或组合, 调用 processEvents() 控制传递哪些事件.
QAbstractEventDispatcher 还允许将外部事件循环与 Qt 事件循环集成.
参见 QEventLoop, QCoreApplication, QThread.
成员函数
QAbstractEventDispatcher::QAbstractEventDispatcher(QObject *parent = Q_NULLPTR)
Constructs a new event dispatcher with the given parent.
QAbstractEventDispatcher::~QAbstractEventDispatcher()
Destroys the event dispatcher.
[signal]
void QAbstractEventDispatcher::aboutToBlock()
This signal is emitted before the event loop calls a function that could block.
参见 awake().
[signal]
void QAbstractEventDispatcher::awake()
This signal is emitted after the event loop returns from a function that could block.
参见 wakeUp() and aboutToBlock().
bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, void *message, long *result)
Sends message through the event filters that were set by installNativeEventFilter(). This function returns true
as soon as an event filter returns true
, and false otherwise to indicate that the processing of the event should continue.
Subclasses of 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 for details.
This function was introduced in Qt 5.0.
参见 installNativeEventFilter() and QAbstractNativeEventFilter::nativeEventFilter().
void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
Installs an event filter filterObj for all native event filters received by the application.
The event filter filterObj receives events via its 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 and handled by the standard Qt event filtering, e.g. QObject::installEventFilter().
If multiple event filters are installed, the filter that was installed last is activated first.
Note: The filter function set here receives native messages, that is, MSG or XEvent structs.
For maximum portability, you should always try to use QEvent objects and QObject::installEventFilter() whenever possible.
This function was introduced in Qt 5.0.
参见 QObject::installEventFilter().
[static]
QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread = Q_NULLPTR)
Returns a pointer to the event dispatcher object for the specified thread. If thread is zero, the current thread is used. If no event dispatcher exists for the specified thread, this function returns 0.
Note: 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() as soon as possible.
[pure virtual]
bool QAbstractEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process. Returns 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 flag.
If the QEventLoop::WaitForMoreEvents flag is set in flags, the behavior of this function is as follows:
- If events are available, this function returns after processing them.
- If no events are available, this function will wait until more are available and return after processing newly available events.
If the QEventLoop::WaitForMoreEvents flag is not set in flags, and no events are available, this function will return immediately.
Note: This function does not process events continuously; it returns after all available events are processed.
参见 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 is the QWinEventNotifier instance to be registered.
The method should return true if the registration of notifier was sucessful, 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)
Registers notifier with the event loop. Subclasses must implement this method to tie a socket notifier into another event loop.
int QAbstractEventDispatcher::registerTimer(int interval, Qt::TimerType timerType, QObject *object)
Registers a timer with the specified interval and timerType for the given object and returns the timer id.
[pure virtual]
void QAbstractEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
Register a timer with the specified timerId, interval, and timerType for the given object.
[pure virtual]
QList<TimerInfo> QAbstractEventDispatcher::registeredTimers(QObject *object) const
Returns a list of registered timers for object. The TimerInfo struct has timerId
, interval
, and timerType
members.
参见 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.
void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilter *filter)
Removes the event filter filter from this object. The request is ignored if such an event filter has not been installed.
All event filters for this object are automatically removed when this object is destroyed.
It is always safe to remove an event filter, even during event filter filter activation (that is, even from within the nativeEventFilter() function).
This function was introduced in Qt 5.0.
参见 installNativeEventFilter() and 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 is the 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. Returns true
if successful; otherwise returns false
.
参见 registerTimer() and 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() and registeredTimers().
[pure virtual]
void QAbstractEventDispatcher::wakeUp()
Wakes up the event loop.
Note: This function is thread-safe
参见 awake().