I'm trying to get gamepad functionality to work in my C++ QT arcade game(yes PacMan) clone app. I'm writing and testing it in Windows for now (I don't have access to a Linux box but eventually I'll test there too hopefully). I have a protected method in my GamePanel class called "initInput" Here is the code for that method:
void GamePanel::initInput()
{
QList<int> lstDevices = QGamepadManager::instance()->connectedGamepads();
if(!lstDevices.isEmpty())
setGamepad(new QGamepad(lstDevices[0], this));
}
void GamePanel::setGamepad(const QGamepad *ptrGamepad)
{
if(mPtrGamepad != nullptr)
delete mPtrGamepad;
mPtrGamepad = const_cast<QGamepad *>(ptrGamepad);
connect(mPtrGamepad, &QGamepad::buttonAChanged, this, &GamePanel::pacManAPressed);
connect(mPtrGamepad, &QGamepad::buttonBChanged, this, &GamePanel::pacManBPressed);
connect(mPtrGamepad, &QGamepad::buttonCenterChanged, this, &GamePanel::pacManCenterPressed);
connect(mPtrGamepad, &QGamepad::buttonGuideChanged, this, &GamePanel::pacManGuidePressed);
connect(mPtrGamepad, &QGamepad::buttonDownChanged, this, &GamePanel::pacManDownPressed);
connect(mPtrGamepad, &QGamepad::buttonLeftChanged, this, &GamePanel::pacManLeftPressed);
connect(mPtrGamepad, &QGamepad::buttonRightChanged, this, &GamePanel::pacManRightPressed);
connect(mPtrGamepad, &QGamepad::buttonUpChanged, this, &GamePanel::pacManUpPressed);
connect(mPtrGamepad, &QGamepad::buttonL1Changed, this, &GamePanel::pacManL1Pressed);
connect(mPtrGamepad, &QGamepad::buttonL2Changed, this, &GamePanel::pacManL2Tilted);
connect(mPtrGamepad, &QGamepad::buttonL3Changed, this, &GamePanel::pacManL3Pressed);
connect(mPtrGamepad, &QGamepad::buttonR1Changed, this, &GamePanel::pacManR1Pressed);
connect(mPtrGamepad, &QGamepad::buttonR2Changed, this, &GamePanel::pacManR2Tilted);
connect(mPtrGamepad, &QGamepad::buttonR3Changed, this, &GamePanel::pacManR3Pressed);
connect(mPtrGamepad, &QGamepad::axisLeftXChanged, this, &GamePanel::pacManAxisLeftXTilted);
connect(mPtrGamepad, &QGamepad::axisLeftYChanged, this, &GamePanel::pacManAxisLeftYTilted);
connect(mPtrGamepad, &QGamepad::axisRightXChanged, this, &GamePanel::pacManAxisRightXTilted);
connect(mPtrGamepad, &QGamepad::axisRightYChanged, this, &GamePanel::pacManAxisRightYTilted);
}
lstDevices ends up being empty. I actually had code in to output using qDebug() and it will always print that there are no devices. Yet Windows in the Settngs/Control Panel / Devices and Printers shows my "Gamepad F310" and I just tried to play a game I have on Steam with it and it worked. What may I be doing wrong? Do I need to do any more calls to populate the connectedDevices or something?