Drop Queued keyboard and mouse events
Is there a way to turn off queueing of keyboard and mouse events?
What I want:
If a keyboard event comes in before the previous event has been processed it does't get added the the event queue; it will get dropped.
In my event queue thread (main application thread) I can make calls that can block for up to 2 seconds. While the thread is blocking, if the user presses some keys they will be queued up and processed after the block is done. The problem I am facing is sometimes the users key events will cause more 2 second blocking calls and cause even more queueing. This will make my GUI pretty much stop and is not my desired affect. I don't mind if the GUI freezes for 2 seconds here or there, but it's when the gui freezes for minutes it's a problem.
Blocking calls in the GUI threads sounds quite evil. Why not put those into a background thread? Make it signal the foreground thread once something is done. Simply use Qt's thread-aware signal-slot mechanism.
Hope, you don't mind for my short recipe;)
Even if i remove the non blocking calls from the main event thread I still need a way to get rid of queue events. It still causes undesired affects. Is this possible? and if it is how?
I don't think your architecture is all right. Anyways, there was something to eat queued events... QCoreApplication::processEvents(). Maybe, you want to give it a try. Of course you can't do it directly in QML.
I would just introduce a boolean sentinel:
- Set it to true before you do your work.
- Check it in the slots connected to your UI elements. If it's true do nothing, if it's false start the workload.
- After your work is done reset it to false.