QEvent, QEventLoop, batch process events?
-
Hey!
So I'm working on a worker process for my app. I decided to use QEvents as I can configure their priority and "control" what gets executed in what order - more or less thanks to priority.
One thing I would like to do is to push an update function after certain jobs have finished.
say I have low priority jobs, once all of them get processed I would like to push "update" function, whereas if I send priority jobs I would like to push "update" after each event gets processed...
Pushing update for high priority jobs seems easy, I just add the "update" call to the priority event, but when it comes to "low priority", I'm not sure how to batch group them and update?
How can I approach it?
TIA
-
@Dariusz
I'm not sure either! Not sure how you mean you can "configure their priority and "control" what gets executed in what order". Priority must be something you are adding.but when it comes to "low priority", I'm not sure how to batch group them and update?
The obvious would be to put your events on some sort of queue, or different queues according to priority. Process higher priority queues before lower priority ones. When, say, the higher priority queue is empty you can then decide to process all events in lower priority queue. When that queue becomes empty that's how you know you have processed them all.
?
-
@JonB Sound about right but I don't control the queue. Its done by Qt, QEventLoop queue, but in my case QThread/QObject queue that I run. So far I was thinking that I could do some wacky local object based filtering to decide when to do what but not sure....
-
Hi,
Out of curiosity, shouldn't you rather use a state machine to model that ?
-
@SGaist Except openGL I don't really know of them. Will google it a bit.
On a side note, is there a way to find out size of current thread/object queue ? I read some stack overflow ideas where I can export
extern uint qGlobalPostedEventsCount();
To get it, but I'm not sure if it returns global thread event count or local thread as explanation was a bit confusing...So far I was able to specify/control batching in my local obejct which is awesome. But I just need to know the size of queue to determine number of updates during the processing time... Any hints? Could really use object::getPostEventQueueSize() as well as something like. object::clearPostEventQueue() to cancel all signals.
-
Even two if you take the QtScxml module.
Well, I am not behind the design of the system so I can just offer some thoughts. I would say that if you need that level of control of the event loop, you might not be using the right tool for your use case.