Let's start with adding the Qt Gamepad add-on to our project by editing the jrgame.pro file:
QT += core gui widgets gamepad
This will make the headers of the library available to our project and tell qmake to link the project against this library. Now add the following code to the constructor of the MyScene class:
QList<int> gamepadIds = QGamepadManager::instance()->connectedGamepads(); if (!gamepadIds.isEmpty()) { QGamepad *gamepad = new QGamepad(gamepadIds[0], this); connect(gamepad, &QGamepad::axisLeftXChanged, this, &MyScene::axisLeftXChanged); connect(gamepad, &QGamepad::axisLeftYChanged, this, &MyScene::axisLeftYChanged); }
The code is pretty straightforward. First, we use QGamepadManager::connectedGamepads ...