PDA

View Full Version : In layman's terms, what are signals and slots?



ayanda83
18th August 2012, 14:30
Hi everyone, i'm new to OOP and Qt programming. can anyone define what signals and slots are in true layman's terms. I've red the definition in a book but i'm failing to grasp the concept of what they are and what purpose to they serve.

QT++
18th August 2012, 14:52
A signal is the action required by the user and the slot if the action performed by the program.

For example a signal would be clicking a button. The resulting slot could be to close the application.

ChrisW67
19th August 2012, 08:10
A signal is emitted by an object to indicate that some event has occurred. For example a signal might indicate that the text in a text box has been edited, or that a new piece of data has arrived over the network. A signal can be connected zero, one or more objects that are interested to know about these events. The function in the receiving object is a slot and can do whatever it like in response to the signal, for example copy the edited text somewhere or process the received data. The object issuing the signals does not need to know anything about the objects receiving the signal: the objects are considered loosely coupled.

Signals and slots are the Qt answer to the Observer Pattern.