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. ...