Understanding events and the event loop
Qt is an event-based system, and all GUI applications are event-driven. In an event-driven application, there is usually a main loop that listens for events and then triggers a callback function when one of those events is detected. Events can be spontaneous or synthetic. Spontaneous events come from the outside environment. Synthetic events are custom events generated by the application. An event in Qt is a notification that represents something that has happened. Qt events are value types, derived from QEvent
, which offers a type enumeration for each event. All events that arise inside a Qt application are encapsulated in objects that inherit from the QEvent
class. All QObject
derived classes can override the QObject::event()
function in order to handle events targeted by their instances. Events can come from both inside and outside the application.
When an event occurs, Qt produces an event object by constructing an appropriate QEvent
subclass...