PDA

View Full Version : Event Handler



sterling
29th October 2014, 01:40
I have a need (real) to process raw events from the QApplication. What I have been unable to discern as yet is how to convert a raw QEvent into QFocusEvent, QKeyEvent, and such. Is there a place in the Qt sources where I can look for the conversions and get a good definition of the contents (other than type) of a QEvent? Specifically, how is an event mapped to a specific QObject and where is the extra information such as which key was pressed or mouse button pressed?

d_stranz
29th October 2014, 05:02
You use QEvent::type() to find out what it is, and qobject_cast< whatever * >( event ) to cast it to a QEvent-based instance of that type. QEvent types derived from QInputEvent will contain the QObject pointer of the instance that generated them, and other event classes derived from QEvent may have them as well.

anda_skoa
29th October 2014, 10:36
I don't think qobject_cast will work on QEvent as it is not a QObject derived class.

But checking type plus static_cast or dynamic_cast should work fine.

One way to see all events and the objects they are sent to is to install an event filter on the QApplication instance.
The eventFilter() method gets both the event and the receiver object.

Cheers,
_

d_stranz
29th October 2014, 23:15
I don't think qobject_cast will work on QEvent as it is not a QObject derived class.

Duh, yes, my mistake.