Unsolved Unable to get QML Gamepad to work
-
Hi,
I am trying to use gamepad input from QML but cannot figure out how to use the Gamepad and GamepadManager components correctly. The result is that the operating system (same on Linux and Windows) sees connects and button presses just fine but in QML the application sees the gamepad if it is already plugged-in on application start but then does not get any changes.
Since the documentation is not much more that a plain list of some properties, I started guessing on how to make use of what is there. So here is my first approach on trying to get some feedback.
Connections { target: GamepadManager onConnectedGamepadsChanged: { console.log("connected gamepads changed") if (GamepadManager.connectedGamepads.length > 0) { gamepad.deviceId = GamepadManager.connectedGamepads[0] console.log("found: ", gamepad.name) } } }
... no output comes out of that.
Another approach was to just create a Gamepad:
Gamepad { id: gamepad Component.onCompleted: { deviceId = GamepadManager.connectedGamepads[0] console.log("Gamepad id: ", deviceId) console.log("Gamepad name: ", name) console.log("Gamepads: ", GamepadManager.connectedGamepads) } }
... given the gamepad is connected when the application starts, the output looks mildly promising, telling
me some id for bothdeviceId
andGamepadManager.connectedGamepads
but not name. ... But well, lets try some buttons. The code is called within a Connections component that is called every second. It's unrelated code that I just use to put the code in. So, the code is executed every secondif (gamepad.connected) { if (gamepad.buttonDown) { console.log("down") } }
... and no output is given regardless of me pressing buttons or not.
So, I guess I am using GamepadManager and Gamepad incorrectly. Can someone show me a small example on how to get button presses out of my gamepad with QML?
Thank you
icw -
Apparently there is some black magic involved.
If I copy and open the configureButtons example, it works.
If I rename the example folder and pro file to configureButtons2, it does not work anymore.This means, following the example code line by line will not make it work in your application.
What helps though is to just rename your project to configureButtons ... That way the gamepad works as expected. -_-