QAbstractEventDispatcher Class

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

Header: #include <QAbstractEventDispatcher>
qmake: QT += core
Inherits: QObject

Public Types

Public Functions

QAbstractEventDispatcher(QObject *parent = nullptr)
virtual ~QAbstractEventDispatcher()
bool filterNativeEvent(const QByteArray &eventType, void *message, long *result)
void installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
int registerTimer(int interval, Qt::TimerType timerType, QObject *object)
void removeNativeEventFilter(QAbstractNativeEventFilter *filter)
  • 16 public functions inherited from QObject

Static Public Members

QAbstractEventDispatcher *instance(QThread *thread = nullptr)
  • 5 static public members inherited from QObject
typedef QObjectList

Macros

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject
  • 8 protected functions inherited from QObject

Detailed Description

An event dispatcher receives events from the window system and other sources. It then sends them to the QCoreApplication or QApplication instance for processing and delivery. QAbstractEventDispatcher provides fine-grained control over event delivery.

For simple control of event processing use QCoreApplication::processEvents().

For finer control of the application's event loop, call 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 install it with QCoreApplication::setEventDispatcher() or QThread::setEventDispatcher() before a default event dispatcher has been installed.

The main event loop is started by calling QCoreApplication::exec(), and stopped by calling QCoreApplication::exit(). Local event loops can be created using QEventLoop.

Programs that perform long operations can call processEvents() with a bitwise OR combination of various QEventLoop::ProcessEventsFlag values to control which events should be delivered.

QAbstractEventDispatcher also allows the integration of an external event loop with the Qt event loop.

See also QEventLoop, QCoreApplication, and QThread.

Member Function Documentation

QAbstractEventDispatcher::QAbstractEventDispatcher(QObject *parent = nullptr)

Constructs a new event dispatcher with the given parent.

[virtual] QAbstractEventDispatcher::~QAbstractEventDispatcher()

Destroys the event dispatcher.

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.

See also installNativeEventFilter() and QAbstractNativeEventFilter::nativeEventFilter().

void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)

Installs an event filter filterObj for all native events 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.

See also QObject::installEventFilter().

[static] QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread = 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.

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.

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.

See also installNativeEventFilter() and QAbstractNativeEventFilter.