I've followed this tutorial to create a widget in which i can render using SDL, at the end of the tutorial the author mentions that it should be possible to use 'SDL_PollEvent' in the update function so I've created this update function with following content:
SDL_Event sdl_event;
while(SDL_PollEvent(&sdl_event))
{
switch(sdl_event.type){
case SDL_KEYDOWN:
LOG_CRITICAL("KeyDown");
break;
case SDL_KEYUP:
LOG_CRITICAL("KeyUp");
break;
default:
LOG_CRITICAL("Other Event");
break;
}
}
And even when i click or hold down a button LOG_CRITICAL does not run. Is there something I'm doing wrong or is there another way to handle input?
I've tried running another thread to handle the input however apparently you can only handle events in the main thread.
Edit: It started to work when i changed SDL_PollEvent to SDL_WaitEvent. My rendering is done in a different thread so rendering was still hapenning but it was impossible to close or resize the window (i assume qt's thread is frozen because of SDL_WaitEvent).
I could also change while (SDL_WaitEvent) to if (SDL_WaitEvent) and the window would only freeze when i was clicking a button but there has to be a "better" way to do it?