Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event propagation in Qt

Tags:

qt

qt-events

I've just the documentation on the Qt event system and the QEvent class. I'm interested in the behavior of the QObject::event() method. The documentation states:

This virtual function receives events to an object and should return true if the event e was recognized and processed.

What is the expected behavior when false is returned from the event() method? What else is attempted in order to handle the event? Is the event automatically forwarded to the parent object?

Note: I know the source is available, and I do have a copy. I'm ideally looking for some piece of documentation addressing this behavior.

like image 844
André Caron Avatar asked May 09 '11 19:05

André Caron


People also ask

How to handle event in Qt?

When an event occurs, Qt creates an event object to represent it by constructing an instance of the appropriate QEvent subclass, and delivers it to a particular instance of QObject (or one of its subclasses) by calling its event() function.

Is Qt event driven?

The Qt Framework is an industrial-strength, cross-platform, and multi-platform GUI toolkit that runs on Windows, GNU Linux, macOS X, and other Mac systems. The toolkit has been compiled into embedded systems and mobile devices.

How does Qt event loop work?

Qt's event loop starts the moment the underlying application's exec() function gets called. Once started, the loop repeatedly checks for something to happen in the system, such as user-input through keyboard/mouse.


1 Answers

I believe the best practice is to explicitly forward the events to the base-class event method if you do not wish to filter that event type (e.g. return QObject::event(event);) since the event function delegates events to specific handlers (e.g. QWidget::keyPressEvent).

QCoreApplication::notify propogates events based on the return value. On true, it considers the event as consumed and stops. Otherwise, the event is passed to the object's parent. For more information, see Events and Filters and Another Look at Events.

like image 127
Judge Maygarden Avatar answered Sep 21 '22 03:09

Judge Maygarden