Return to site

Qt creator signals and slots

broken image

A signal is emitted when a particular event occurs. In Qt, we have an alternative to the callback technique: We use signals and slots.

broken image

Secondly, the callback is strongly coupled to the processing function since the processing function must know which callback to call. We can never be certain that the processing function will call the callback with the correct arguments. Callbacks have two fundamental flaws: Firstly, they are not type-safe. The processing function then calls the callback when appropriate. A callback is a pointer to a function, so if you want a processing function to notify you about some event you pass a pointer to another function (the callback) to the processing function. Older toolkits achieve this kind of communication using callbacks. For example, if a user clicks a Close button, we probably want the window's close() function to be called. More generally, we want objects of any kind to be able to communicate with one another. In GUI programming, when we change one widget, we often want another widget to be notified.

broken image

The signals and slots mechanism is a central feature of Qt and probably the part that differs most from the features provided by other frameworks. Signals and slots are used for communication between objects.

broken image