Return to site

Qt creator connect slots to signals

broken image

The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot. Qt's widgets have many pre-defined slots, but it is common practice to subclass widgets and add your own slots so that you can handle the signals that you are interested in. A slot is a function that is called in response to a particular signal. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A signal is emitted when a particular event occurs. In Qt, we have an alternative to the callback technique: We use signals and slots. While successful frameworks using this method do exist, callbacks can be unintuitive and may suffer from problems in ensuring the type-correctness of callback arguments.

broken image

The processing function then calls the callback when appropriate.

broken image

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. Other 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.

broken image

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