Qt Gamepad documentation



  • Hello.

    I want to develop an application that would handle gamepad events. Many gamepads will be connected to the computer, and the program should know what button of what gamepad have pressed.

    I haven't found how to work with many gamepads with QGamepad.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Looks like you are searching for the QGamepadManager class which looks like it has its documentation missing. However a quick look at the module examples should get you going.

    Hope it helps.



  • And if I want to connect all signals button...Changed to one slot, should I connect them one by one? Or I can get list of buttons and connect it to slot in a loop?


  • Lifetime Qt Champion

    You can use QMetaType inspection to get all signals and then filter them by name before creating the connections.



  • And I tried examples, and Qt doesn't see some of my gamepad keys. I use Genius g-08-xu gamepad. It works perfectly in another software, but Qt doesn't see buttons 3 and 6.



  • And I tried this example: http://www.ics.com/blog/whats-new-qt-570-qt-gamepad but it says that I have only one gamepad, but I have connected two gamepads. If I press any button in one of them, it prints a message that button was pressed, but shows the same device ID. And 3 and 6 buttons on Genius g-08-xu don't work with this example too.


  • Lifetime Qt Champion

    What OS are you on ?



  • Linux. I tried on Windows (minGW) too, but it doesnt't work at all. Examples don't see any gamepads.


  • Lifetime Qt Champion

    Did you check that the plugin get correctly loaded ?



  • How cat I check it?


  • Lifetime Qt Champion

    Add QT_DEBUG_PLUGINS to the environment variables in the Run part of the Project panel and set it to 1.

    You'll have more information on the debug output.



  • QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads" ...
    QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepad.dll"
    Found metadata in lib C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepad.dll, metadata=
    {
        "IID": "com.bsquask.Qt.Gamepad.QtGamepadBackendFactoryInterface.5.5",
        "MetaData": {
            "Keys": [
                "xinput"
            ]
        },
        "className": "QXInputGamepadBackendPlugin",
        "debug": false,
        "version": 329472
    }
    
    
    Got keys from plugin meta data ("xinput")
    QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepadd.dll"
    Found metadata in lib C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepadd.dll, metadata=
    {
        "IID": "com.bsquask.Qt.Gamepad.QtGamepadBackendFactoryInterface.5.5",
        "MetaData": {
            "Keys": [
                "xinput"
            ]
        },
        "className": "QXInputGamepadBackendPlugin",
        "debug": true,
        "version": 329472
    }
    
    
    "The plugin 'C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepadd.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
             not a plugin
    QFactoryLoader::QFactoryLoader() checking directory path "C:/build-gamepadexample-Desktop_Qt_5_7_0_MinGW_32bit-Release/release/gamepads" ...
    loaded library "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepad.dll"
    loaded library "xinput1_4.dll"
    loaded library "xinput1_3.dll"
    

    Windows 7 x86 (32 bit)



  • I tried to use msvc 2015 instead of MinGW, but I got the same problem.



  • Hi, if you're compiling in Debug mode, try instead to compile in Release mode.



  • Same problem:

    Starting C:\build-gamepadexample-Desktop_Qt_5_7_0_MinGW_32bit-Release\release\gamepadexample.exe...
    QGamePadManager Demo
    
    QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads" ...
    QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepad.dll"
    Found metadata in lib C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepad.dll, metadata=
    {
        "IID": "com.bsquask.Qt.Gamepad.QtGamepadBackendFactoryInterface.5.5",
        "MetaData": {
            "Keys": [
                "xinput"
            ]
        },
        "className": "QXInputGamepadBackendPlugin",
        "debug": false,
        "version": 329472
    }
    
    
    Got keys from plugin meta data ("xinput")
    QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepadd.dll"
    Found metadata in lib C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepadd.dll, metadata=
    {
        "IID": "com.bsquask.Qt.Gamepad.QtGamepadBackendFactoryInterface.5.5",
        "MetaData": {
            "Keys": [
                "xinput"
            ]
        },
        "className": "QXInputGamepadBackendPlugin",
        "debug": true,
        "version": 329472
    }
    
    
    "The plugin 'C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepadd.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
             not a plugin
    QFactoryLoader::QFactoryLoader() checking directory path "C:/build-gamepadexample-Desktop_Qt_5_7_0_MinGW_32bit-Release/release/gamepads" ...
    loaded library "C:/Qt/Qt5.7.0/5.7/mingw53_32/plugins/gamepads/xinputgamepad.dll"
    loaded library "xinput1_4.dll"
    loaded library "xinput1_3.dll"
    Number of gamepads: 0
    
    
    


  • Hmm, I checked and it seems Qt Gamepad does not support all the different gamepads available on WIndows :-( I.e. the plugin loads fine but no gamepads are detected, more discussion here

    Also you can try emulating a Microsoft device like an Xbox360-controller, for example I can use my Playstation4 controller by installing DS4Windows



  • I'll try it later.

    But why Qt can support only part of gamepads? My gamepads are very old and work both in Windows and Linux without additional drivers.



  • DS4Windows doesn't see my gamepads. But Windows Control panel sees and shows pressed buttons.



  • Because your gamepad is 12 years old (or more) I think it doesn't support the standard DirectX interface, only Windows control panel, that's why Qt is blind to it.
    Also, when playing a 64-bit (only) game like BattleField1, I think such game will exhibit the same problem as Qt, i.e. not see your gamepad :-(



  • @TimurE
    I work at Win10 64 bits and QT5.7.0 ,msvc14。It canwork at this code.
    Gamepad::Gamepad(QObject *parent) : QObject(parent)
    , m_gamepad(0)
    {
    m_gamepad = new QGamepad(0,this);//or just m_gamepad = new QGamepad; is ok//
    connect(m_gamepad,&QGamepad::connectedChanged,this,&MMGamepad::connectedChangedEvent);
    qDebug() << "A new gamepad:"<<m_gamepad->isConnected();// when start is false
    }
    void Gamepad::connectedChangedEvent(bool value)
    {
    if(value)
    {
    qDebug() << "Gamepad:: decive is connect!" ;
    }
    else
    {
    qDebug() << "Gamepad:: decive is disconnect!" ;
    }
    }
    and you can get any signal after"Gamepad:: decive is connect".



  • @xiuscut said in Qt Gamepad documentation:

    connectedChangedEvent

    also remenber "QT += gamepad" in .pro and #include <QtGamepad/QGamepad>


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.