PDA

View Full Version : Use of SDL within QT, joystick application



jhowland
17th October 2013, 20:23
I have an application that communicates (using primarily UDP sockets) with a variety of sensors, and with the user via button pushes, etc. It has been working fine. Now the users want to add a USB joystick to it.

I did the requisite Google searches, and found joypick. https://code.google.com/p/joypick/. I copied much of the code from joypick into my application, making changes as necessary to fit my windowing approach, etc.

Although joypick compiles and executes just fine, when I use its qjoystick.cpp (without changes) in my code, it hangs up at a line


SDL_Event event;

SDL_PollEvent(&event);

joypick doesn't do this. My suspicion is that the SDL event loop is somehow getting robbed of events by the qt event loop, but I dont know how to prevent it. joypick doesn't seem do anything special along these lines. Any ideas? I detect and initialize the joystick just fine, can count its buttons and axes, etc, but the event poll never returns

Thanks in advance

I guess I should have indicated that I am using Windows 7, QT 4.7.4 with mingw, and SDL 1.2.15

jhowland
17th October 2013, 23:09
Another piece of information to add:

I use multiple QTimers in my program. joypick (the QT/SDL application that works) only uses one, and the SDL_PollEvent is within its timeout slot.

When I disable all of my timers, leaving only the joystick timer, the joystick part of my code works as intended.

Unfortunately, I really need several timers in my application. I could of course use just one at the highest rate I need and "multiplex" but I dont really want that complexity. So I'm still looking for a solution.

anda_skoa
18th October 2013, 10:58
Integrating event loops is not an easy task. usually it requires a specialized event dispatcher class.

Have you tried running the SDL event loop in a thread?

Cheers,
_