O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connecting signals and slots

Signals and slots can be connected and disconnected dynamically using the  QObject::connect() and QObject::disconnect() functions. A regular, signal-slot connection is defined by the following four attributes:

  • An object that changes its state (sender)
  • A signal in the sender object
  • An object that contains the function to be called (receiver)
  • A slot in the receiver

If you want to make the connection, you need to call the QObject::connect function and pass these four parameters to it. For example, the following code can be used to clear the input box whenever the button is clicked on:

connect(button,   &QPushButton::clicked,
        lineEdit, &QLineEdit::clear);

Signals and slots in this code are specified using a standard ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required