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

Accessing signals and slots in scripts

QJSEngine also offers the capability to use signals and slots. The slot can be either a C++ method or a JavaScript function. The connection can be made either in C++ or in the script.

First, let's see how to establish a connection within a script. When a QObject instance is exposed to a script, the object's signals become the properties of the wrapping object. These properties have a connect method that accepts a function object that is to be called when the signal is emitted. The receiver can be a regular slot or a JavaScript function. The most common case is when you connect the signal to an anonymous function:

pushButton.toggled.connect(function() {
    console.log('button toggled!');
});

If you need ...

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