Reputation: 53
that's my main.cpp
#include "mainwindow.h"
#include <QApplication>
#include "SDL.h"
#include <QDebug>
#undef main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
SDL_Window *window = nullptr;
SDL_Surface *windowSurface = nullptr;
SDL_Init(SDL_INIT_VIDEO);
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,"1");
SDL_Init( SDL_INIT_JOYSTICK);
SDL_Joystick *joystick = SDL_JoystickOpen(0);
qDebug()<<SDL_JoystickName(joystick);
qDebug()<<(SDL_JoystickNumAxes(joystick));
qDebug()<<(SDL_JoystickNumButtons(joystick));
window = SDL_CreateWindow("SDL CodingMadeEasy Series", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
windowSurface = SDL_GetWindowSurface(window);
SDL_Event ev;
int x;
bool isRunning = true;
while(isRunning)
{
while(SDL_PollEvent(&ev) != 0)
{
if(ev.type == SDL_JOYBUTTONDOWN)
{
qDebug()<<"Button Clicked";
}
}
// Drawing the current image to the window
SDL_UpdateWindowSurface(window);
}
return a.exec();
}
it can recognize the PS4 Controller , as it prints out the qDebug lines. i tried changing the ev.type == ( SOMETHING ELSE NOT JOYSTICK RELATED ) and it worked just fine, so apparently there is a problem with the JOYBUTTONDOWN.
any help?
Upvotes: 1
Views: 947
Reputation: 53
it was fixed by Enabling joystick events
SDL_JoystickEventState(SDL_ENABLE);
Upvotes: 2