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

Creating signals and slots

If you create a QObject subclass (or a QWidget subclass, as QWidget inherits QObject), you can mark a method of this class as a signal or a slot. If the parent class had any signals or non-private slots, your class will also inherit them.

In order for signals and slots to work properly, the class declaration must contain the Q_OBJECT macro in a private section of its definition (Qt Creator has generated it for us). When the project is built, a special tool called Meta-Object Compiler (moc) will examine the class's header and generate some extra code necessary for signals and slots to work properly.

Keep in mind that moc and all other Qt build tools do not edit the project files. Your C++ files are passed to the ...

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