Events are objects specifically designed for communication. They consist of event-signals and event-parameters. In the QP Frameworks underlying QM, events are subclasses of the QEvt base class. QM incorporates such events by recognizing that a given class is a (direct or indirect) subclass of QEvt and by providing the event stereotype for those classes. Additionally, event classes can be placed in packages with the event stereotype
The event-signal provides information about the occurrence conveyed by the event. In QM, event-signals are used as transition triggers. Event-signals are typically enumerated in a header file, as illustrated in the following screen shot:
Currently, QM does not provide any more support for handling event-signals. In the future, QM will add support for partitioning the signal space and for associating event-signals with custom event classes.
The purpose of subclassing QEvt is to create events with parameters. These parameters are added in subclasses of QEvt as attributes of the event classes.
For example, the event class ObjectImageEvt in the screen shot above specifies the following event parameters:
Once the event classes are specified in the QM model, you typically need to provide the declaration of these classes in a header file. A header file is the right place, because events are shared among components, so they typically need to be included in multiple modules (.c or .cpp files).
You can declare event classes in a header file either one at a time:
Alternatively, if you placed all your events in a dedicated package, you can simply generate declaration of the whole package:
The latter declaration (the whole event package) results in the following generated code:
As mentioned before, the purpose of custom event classes is to represent events with parameters. So now, in the code you need to access the event parameters. The QP/C and QP/C++ frameworks provide a special macro Q_EVT_CAST() to encapsulate down-casting the current event e to the specific subclass of QEvt and then to conveniently access the event parameters. This is illustrated in the screen shot below: