Adding gamepad support
The player can use the keyboard to play our game, but it would be nice to also allow playing it using a gamepad. Fortunately, Qt provides the Qt Gamepad add-on that allows us to do this easily. As opposed to Qt Essentials (for example, Qt Widgets), add-ons may be supported on a limited number of platforms. As of Qt 5.9, Qt Gamepad supports Windows, Linux, Android, macOS, iOS, and tvOS (including the tvOS remote).
Working with gamepads in Qt
The starting point of the gamepad API is the QGamepadManager
class. The singleton object of this class can be obtained using the QGamepadManager::instance()
function. It allows you to request the list of identifiers of the available gamepads using the connectedGamepads()
function. The gamepadConnected()
signal can be used to detect new gamepads on the fly. QGamepadManager
also provides API for configuring buttons and axes on the gamepad and is able to save the configuration to the specified settings file.
After you detected that one...