Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Unable to get QML Gamepad to work
Forum Updated to NodeBB v4.3 + New Features

Unable to get QML Gamepad to work

Scheduled Pinned Locked Moved Unsolved Game Development
2 Posts 1 Posters 765 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • deleted71D Offline
    deleted71D Offline
    deleted71
    wrote on last edited by deleted71
    #1

    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 both deviceId and GamepadManager.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 second

    if (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

    1 Reply Last reply
    0
    • deleted71D Offline
      deleted71D Offline
      deleted71
      wrote on last edited by deleted71
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved