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

Gamepad input

Handling gamepad events is a very common task when developing a game. Fortunately, Qt provides Qt Gamepad module for this purpose. We already learned how to use it in C++. Now let's see how to do this in QML applications.

To enable Qt Gamepad module, add QT += gamepad to the project file. Next, import the QML module by adding the following line at the beginning of your QML file:

import QtGamepad 1.0

This import allows you to declare objects of the Gamepad type. Add the following object inside your top-level QML object:

 Gamepad {     id: gamepad     deviceId: GamepadManager.connectedGamepads.length > 0 ?          GamepadManager.connectedGamepads[0] : -1 }

The GamepadManager object allows us to list identifiers of gamepads available in the system. ...

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