Signals and slots

To trigger functionality as a response to something that happens in an application, Qt uses a mechanism of signals and slots. This is another important feature of the QObject class. It's based on connecting a notification (which Qt calls a signal) about a change of state in some object with a function or method (called a slot) that is executed when such a notification arises. For example, if a button is pressed, it emits (sends) a clicked() signal. If some method is connected to this signal, the method will be called whenever the button is pressed.

Signals can have arguments that serve as a payload. For example, an input box widget (QLineEdit) has a textEdited(const QString &text) signal that's emitted when the user edits ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.