Pauses/stop QObjects inside QThread event loop
-
wrote on 9 Nov 2019, 22:06 last edited by
Hey
I'm in need of pausing a certain QObject running in the QThread event loop so the object::event() does not fire. I want it to still receive events, but I don't want it to execute them until I unblock the loop...
How can I do it ?
Regards
Dariusz -
Hi,
What kind of event do you have in mind ?
-
wrote on 9 Nov 2019, 22:28 last edited by
@SGaist said in Pauses/stop QObjects inside QThread event loop:
Hi,
What kind of event do you have in mind ?
Well say I send 100k events to my Qobject. I would like to pause its event loop for a while and resume it later.
-
How are you sending these events ? What do they trigger in your object ?
-
wrote on 9 Nov 2019, 22:31 last edited by
QObject::event() filters events it receives (which I send via qApp::postEvent(object,event);) and processes them accordingly. I was thinking I could do while(pause)QThread::msleep(1); in the
QObject::Event(QEvent*e);
but that feels... "bad"... -
Again, can you explain why you are using events directly ?
What are you doing in these objects ? -
wrote on 9 Nov 2019, 23:17 last edited by
I'm using them to do the processing and control order of my work via Qevent/priority it provides. Qt don't send any events to it (as fara s I'm aware) so its just my processing unit.
-
QObject has no event loop, the event loop is in QCoreApplication and siblings.
You can not just stop the one from you main application. As for QThread you can interrupt the thread but I'm really not sure that's the best way to handle your situation.
From the looks of it, you seem to have to create a queue of the events received and store these there while in pause mode and then empty that queue on restart if that makes sense.
9/9