QtBase  v6.3.1
Classes | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QAbstractEventDispatcher Class Referenceabstract

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

#include <qabstracteventdispatcher.h>

Inheritance diagram for QAbstractEventDispatcher:
Inheritance graph
[legend]
Collaboration diagram for QAbstractEventDispatcher:
Collaboration graph
[legend]

Classes

class  TimerInfo
 

Signals

void aboutToBlock ()
 
void awake ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 

Public Member Functions

 QAbstractEventDispatcher (QObject *parent=nullptr)
 
 ~QAbstractEventDispatcher ()
 
virtual bool processEvents (QEventLoop::ProcessEventsFlags flags)=0
 
virtual void registerSocketNotifier (QSocketNotifier *notifier)=0
 
virtual void unregisterSocketNotifier (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 bool unregisterTimer (int timerId)=0
 
virtual bool unregisterTimers (QObject *object)=0
 
virtual QList< TimerInforegisteredTimers (QObject *object) const =0
 
virtual int remainingTime (int timerId)=0
 
virtual void wakeUp ()=0
 
virtual void interrupt ()=0
 
virtual void startingUp ()
 
virtual void closingDown ()
 
void installNativeEventFilter (QAbstractNativeEventFilter *filterObj)
 
void removeNativeEventFilter (QAbstractNativeEventFilter *filterObj)
 
bool filterNativeEvent (const QByteArray &eventType, void *message, qintptr *result)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Static Public Member Functions

static QAbstractEventDispatcherinstance (QThread *thread=nullptr)
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 

Protected Member Functions

 QAbstractEventDispatcher (QAbstractEventDispatcherPrivate &, QObject *parent)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Detailed Description

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

\inmodule QtCore

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, QThread

Definition at line 52 of file qabstracteventdispatcher.h.

Constructor & Destructor Documentation

◆ QAbstractEventDispatcher() [1/2]

QAbstractEventDispatcher::QAbstractEventDispatcher ( QObject parent = nullptr)
explicit

Constructs a new event dispatcher with the given parent.

Definition at line 155 of file qabstracteventdispatcher.cpp.

◆ ~QAbstractEventDispatcher()

QAbstractEventDispatcher::~QAbstractEventDispatcher ( )

Destroys the event dispatcher.

Definition at line 168 of file qabstracteventdispatcher.cpp.

◆ QAbstractEventDispatcher() [2/2]

QAbstractEventDispatcher::QAbstractEventDispatcher ( QAbstractEventDispatcherPrivate dd,
QObject parent 
)
protected

Definition at line 161 of file qabstracteventdispatcher.cpp.

Member Function Documentation

◆ aboutToBlock

void QAbstractEventDispatcher::aboutToBlock ( )
signal

This signal is emitted before the event loop calls a function that could block.

See also
awake()
Here is the caller graph for this function:

◆ awake

void QAbstractEventDispatcher::awake ( )
signal

This signal is emitted after the event loop returns from a function that could block.

See also
wakeUp(), aboutToBlock()
Here is the caller graph for this function:

◆ closingDown()

void QAbstractEventDispatcher::closingDown ( )
virtual

Reimplemented in QEventDispatcherWin32.

Definition at line 333 of file qabstracteventdispatcher.cpp.

◆ filterNativeEvent()

bool QAbstractEventDispatcher::filterNativeEvent ( const QByteArray eventType,
void message,
qintptr 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.

See also
installNativeEventFilter(), QAbstractNativeEventFilter::nativeEventFilter()
Since
5.0

Definition at line 448 of file qabstracteventdispatcher.cpp.

Here is the caller graph for this function:

◆ installNativeEventFilter()

void QAbstractEventDispatcher::installNativeEventFilter ( QAbstractNativeEventFilter filterObj)

\variable QAbstractEventDispatcher::TimerInfo::timerId

The timer's unique id.

\variable QAbstractEventDispatcher::TimerInfo::interval

The timer's interval.

\variable QAbstractEventDispatcher::TimerInfo::timerType

The timer's type

See also
Qt::TimerType

Installs an event filter filterObj for all native events received by the application.

The event filter filterObj receives events via its \l {QAbstractNativeEventFilter::}{nativeEventFilter()} function, which is called for all events received by all threads.

The \l {QAbstractNativeEventFilter::}{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 \l{QEvent} {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.

See also
QObject::installEventFilter()
Since
5.0

Definition at line 395 of file qabstracteventdispatcher.cpp.

Here is the caller graph for this function:

◆ instance()

QAbstractEventDispatcher * QAbstractEventDispatcher::instance ( QThread thread = nullptr)
static

Returns a pointer to the event dispatcher object for the specified thread. If thread is \nullptr, the current thread is used. If no event dispatcher exists for the specified thread, this function returns \nullptr.

{Note:} If Qt is built without thread support, the thread argument is ignored.

Definition at line 180 of file qabstracteventdispatcher.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interrupt()

void QAbstractEventDispatcher::interrupt ( )
pure virtual

Interrupts event dispatching. The event dispatcher will return from processEvents() as soon as possible.

Implemented in TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, DummyEventDispatcher, QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherCoreFoundation, QEventDispatcherUNIX, QEventDispatcherGlib, and QCocoaEventDispatcher.

Here is the caller graph for this function:

◆ processEvents()

bool QAbstractEventDispatcher::processEvents ( QEventLoop::ProcessEventsFlags  flags)
pure virtual

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:

\list

  • 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.

\endlist

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.

Implemented in TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, DummyEventDispatcher, QXcbUnixEventDispatcher, QIOSJumpingEventDispatcher, QAndroidEventDispatcher, QWindowsGuiEventDispatcher, QUnixEventDispatcherQPA, QPAEventDispatcherGlib, QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherUNIX, QEventDispatcherGlib, QEventDispatcherCoreFoundation, and QCocoaEventDispatcher.

◆ registeredTimers()

QList< TimerInfo > QAbstractEventDispatcher::registeredTimers ( QObject object) const
pure virtual

Returns a list of registered timers for object. The TimerInfo struct has timerId, interval, and timerType members.

See also
Qt::TimerType

Implemented in QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherCoreFoundation, QEventDispatcherUNIX, QEventDispatcherGlib, QCocoaEventDispatcher, TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, and DummyEventDispatcher.

Here is the caller graph for this function:

◆ registerSocketNotifier()

void QAbstractEventDispatcher::registerSocketNotifier ( QSocketNotifier notifier)
pure virtual

Registers notifier with the event loop. Subclasses must implement this method to tie a socket notifier into another event loop.

Implemented in QEventDispatcherGlib, QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherCoreFoundation, QEventDispatcherUNIX, QCocoaEventDispatcher, TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, and DummyEventDispatcher.

◆ registerTimer() [1/2]

void QAbstractEventDispatcher::registerTimer ( int  timerId,
qint64  interval,
Qt::TimerType  timerType,
QObject object 
)
pure virtual

◆ registerTimer() [2/2]

int QAbstractEventDispatcher::registerTimer ( qint64  interval,
Qt::TimerType  timerType,
QObject object 
)

Registers a timer with the specified interval and timerType for the given object and returns the timer id.

Definition at line 247 of file qabstracteventdispatcher.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remainingTime()

int QAbstractEventDispatcher::remainingTime ( int  timerId)
pure virtual

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.

See also
Qt::TimerType

Implemented in TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, DummyEventDispatcher, QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherCoreFoundation, QEventDispatcherUNIX, QEventDispatcherGlib, and QCocoaEventDispatcher.

◆ removeNativeEventFilter()

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 \l {QAbstractNativeEventFilter::}{nativeEventFilter()} function).

See also
installNativeEventFilter(), QAbstractNativeEventFilter
Since
5.0

Definition at line 418 of file qabstracteventdispatcher.cpp.

Here is the caller graph for this function:

◆ startingUp()

void QAbstractEventDispatcher::startingUp ( )
virtual

Reimplemented in QEventDispatcherWin32, and QEventDispatcherCoreFoundation.

Definition at line 327 of file qabstracteventdispatcher.cpp.

Here is the caller graph for this function:

◆ unregisterSocketNotifier()

void QAbstractEventDispatcher::unregisterSocketNotifier ( QSocketNotifier notifier)
pure virtual

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.

Implemented in QEventDispatcherGlib, QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherCoreFoundation, QEventDispatcherUNIX, QCocoaEventDispatcher, TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, and DummyEventDispatcher.

◆ unregisterTimer()

bool QAbstractEventDispatcher::unregisterTimer ( int  timerId)
pure virtual

Unregisters the timer with the given timerId. Returns true if successful; otherwise returns false.

See also
registerTimer(), unregisterTimers()

Implemented in TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, DummyEventDispatcher, QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherCoreFoundation, QEventDispatcherUNIX, QEventDispatcherGlib, and QCocoaEventDispatcher.

Here is the caller graph for this function:

◆ unregisterTimers()

bool QAbstractEventDispatcher::unregisterTimers ( QObject object)
pure virtual

Unregisters all the timers associated with the given object. Returns true if all timers were successful removed; otherwise returns false.

See also
unregisterTimer(), registeredTimers()

Implemented in QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherCoreFoundation, QEventDispatcherUNIX, QEventDispatcherGlib, QCocoaEventDispatcher, TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, and DummyEventDispatcher.

Here is the caller graph for this function:

◆ wakeUp()

void QAbstractEventDispatcher::wakeUp ( )
pure virtual

\threadsafe

Wakes up the event loop.

\omit

FIXME - QTBUG-70229

On Unix and Glib event dispatchers, if the dispatcher is already awake when this function is called, it is ensured that the current iteration won't block waiting for more events, but will instead do another event loop iteration.

TODO - does other event dispatchers behave the same?

\endomit

See also
awake()

Implemented in TestEventDispatcher, TestEventDispatcher, DummyEventDispatcher, DummyEventDispatcher, QEventDispatcherWin32, QEventDispatcherWasm, QEventDispatcherUNIX, QEventDispatcherCoreFoundation, QEventDispatcherGlib, and QCocoaEventDispatcher.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: