QAbstractEventDispatcher Class Reference

#include <qabstracteventdispatcher.h>

Inheritance diagram for QAbstractEventDispatcher:

Inheritance graph
[legend]
Collaboration diagram for QAbstractEventDispatcher:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QAbstractEventDispatcher class manages Qt's event queue, excluding GUI-related events.

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 create your instance before you create the QApplication object.

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. For example, the Motif Extension included with Qt includes a reimplementation of QAbstractEventDispatcher that merges Qt and Motif events together.

See also:
QEventLoop, QCoreApplication

Definition at line 38 of file qabstracteventdispatcher.h.

Public Types

typedef QPair< int, int > TimerInfo
typedef bool(*) EventFilter (void *message)

Signals

void aboutToBlock ()
void awake ()

Public Member Functions

 QAbstractEventDispatcher (QObject *parent=0)
 ~QAbstractEventDispatcher ()
virtual bool processEvents (QEventLoop::ProcessEventsFlags flags)=0
virtual bool hasPendingEvents ()=0
virtual void registerSocketNotifier (QSocketNotifier *notifier)=0
virtual void unregisterSocketNotifier (QSocketNotifier *notifier)=0
int registerTimer (int interval, QObject *object)
virtual void registerTimer (int timerId, int interval, QObject *object)=0
virtual bool unregisterTimer (int timerId)=0
virtual bool unregisterTimers (QObject *object)=0
virtual QList< TimerInforegisteredTimers (QObject *object) const=0
virtual void wakeUp ()=0
virtual void interrupt ()=0
virtual void flush ()=0
virtual void startingUp ()
virtual void closingDown ()
EventFilter setEventFilter (EventFilter filter)
bool filterEvent (void *message)

Static Public Member Functions

static QAbstractEventDispatcherinstance (QThread *thread=0)

Protected Member Functions

 QAbstractEventDispatcher (QAbstractEventDispatcherPrivate &, QObject *parent)


Member Typedef Documentation

QAbstractEventDispatcher::TimerInfo

Typedef for QPair<int, int>. The first component of the pair is the timer ID; the second component is the interval.

See also:
registeredTimers()

Definition at line 44 of file qabstracteventdispatcher.h.

QAbstractEventDispatcher::EventFilter

Typedef for a function with the signature

        bool myEventFilter(void *message);

See also:
setEventFilter(), filterEvent()

Definition at line 70 of file qabstracteventdispatcher.h.


Constructor & Destructor Documentation

QAbstractEventDispatcher::QAbstractEventDispatcher ( QObject parent = 0  )  [explicit]

Constructs a new event dispatcher with the given parent.

Definition at line 99 of file qabstracteventdispatcher.cpp.

References d.

00100     : QObject(*new QAbstractEventDispatcherPrivate, parent)
00101 {
00102     Q_D(QAbstractEventDispatcher);
00103     d->init();
00104 }

QAbstractEventDispatcher::~QAbstractEventDispatcher (  ) 

Destroys the event dispatcher.

Definition at line 120 of file qabstracteventdispatcher.cpp.

00121 { }

QAbstractEventDispatcher::QAbstractEventDispatcher ( QAbstractEventDispatcherPrivate ,
QObject parent 
) [protected]

Definition at line 109 of file qabstracteventdispatcher.cpp.

References d.

00111     : QObject(dd, parent)
00112 {
00113     Q_D(QAbstractEventDispatcher);
00114     d->init();
00115 }


Member Function Documentation

QAbstractEventDispatcher * QAbstractEventDispatcher::instance ( QThread thread = 0  )  [static]

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.

Definition at line 132 of file qabstracteventdispatcher.cpp.

References QThreadData::current(), data, QThreadData::get2(), and QObject::thread().

Referenced by QX11Data::clipboardWaitForEvent(), QCoreApplication::hasPendingEvents(), QHostInfo::lookupHost(), and QBasicTimer::stop().

00133 {
00134     QThreadData *data = thread ? QThreadData::get2(thread) : QThreadData::current();
00135     return data->eventDispatcher;
00136 }

Here is the call graph for this function:

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; i.e. 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.

See also:
hasPendingEvents()

Referenced by QX11Data::clipboardWaitForEvent().

bool QAbstractEventDispatcher::hasPendingEvents (  )  [pure virtual]

Returns true if there is an event waiting; otherwise returns false.

Referenced by QCoreApplication::hasPendingEvents().

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.

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.

int QAbstractEventDispatcher::registerTimer ( int  interval,
QObject object 
)

Registers a timer with the specified interval for the given object.

Definition at line 199 of file qabstracteventdispatcher.cpp.

References nextTimerId(), and object.

00200 {
00201     int id = nextTimerId();
00202     registerTimer(id, interval, object);
00203     return id;
00204 }

Here is the call graph for this function:

void QAbstractEventDispatcher::registerTimer ( int  timerId,
int  interval,
QObject object 
) [pure virtual]

Register a timer with the specified timerId and interval for the given object.

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()

Referenced by QBasicTimer::stop().

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()

Referenced by QObject::event().

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

Returns a list of registered timers for object. The timer ID is the first member in each pair; the interval is the second.

Referenced by QObject::event().

void QAbstractEventDispatcher::wakeUp (  )  [pure virtual]

Wakes up the event loop.

See also:
awake()

Referenced by QObjectPrivate::setThreadData_helper().

void QAbstractEventDispatcher::interrupt (  )  [pure virtual]

Interrupts event dispatching; i.e. the event dispatcher will return from processEvents() as soon as possible.

void QAbstractEventDispatcher::flush (  )  [pure virtual]

Flushes the event queue. This normally returns almost immediately. Does nothing on platforms other than X11.

void QAbstractEventDispatcher::startingUp (  )  [virtual]

Definition at line 262 of file qabstracteventdispatcher.cpp.

Referenced by QThreadPrivate::createEventDispatcher(), and QCoreApplication::QCoreApplication().

00263 { }

void QAbstractEventDispatcher::closingDown (  )  [virtual]

Definition at line 266 of file qabstracteventdispatcher.cpp.

Referenced by QCoreApplication::~QCoreApplication().

00267 { }

QAbstractEventDispatcher::EventFilter QAbstractEventDispatcher::setEventFilter ( EventFilter  filter  ) 

Sets the event filter filter. Returns a pointer to the filter function previously defined.

The event filter is a function that receives all messages taken from the system event loop before the event is dispatched to the respective target. This includes messages that are not sent to Qt objects.

The function can return true to stop the event to be processed by Qt, or false to continue with the standard event processing.

Only one filter can be defined, but the filter can use the return value to call the previously set event filter. By default, no filter is set (i.e. the function returns 0).

Definition at line 307 of file qabstracteventdispatcher.cpp.

References d.

00308 {
00309     Q_D(QAbstractEventDispatcher);
00310     EventFilter oldFilter = d->event_filter;
00311     d->event_filter = filter;
00312     return oldFilter;
00313 }

bool QAbstractEventDispatcher::filterEvent ( void *  message  ) 

Sends message through the event filter that was set by setEventFilter(). If no event filter has been set, this function returns false; otherwise, this function returns the result of the event filter function.

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.

See also:
setEventFilter()

Definition at line 328 of file qabstracteventdispatcher.cpp.

References d.

Referenced by QEventDispatcherX11::processEvents(), and x11EventSourceDispatch().

00329 {
00330     Q_D(QAbstractEventDispatcher);
00331     if (d->event_filter)
00332         return d->event_filter(message);
00333     return false;
00334 }

void QAbstractEventDispatcher::aboutToBlock (  )  [signal]

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

See also:
awake()

Referenced by QEventDispatcherGlib::processEvents(), and QEventDispatcherUNIX::processEvents().

void QAbstractEventDispatcher::awake (  )  [signal]

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

See also:
wakeUp() aboutToBlock()

Referenced by QEventDispatcherGlib::processEvents(), and QEventDispatcherUNIX::processEvents().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:39:12 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1