"I am ready to receive Signals" signal
-
Is there a signal that is emitted with the event loop starts running?
Suppose I have a class
Aand classBwith different Thread affinity;Alives on the main thread, andBlives on a second thread.- main thread instantiates
B - invokes
moveToThread(secondThread)onB - invokes
secondThread->start() - main thread instantiates
A - main thread will do
connect(A, someSignal, B, someSlot) - invokes
QtApplication::exec()
Now,
Abeing a GUI andBbeing some module, I needAto obtain some data fromBthat is needed forAto display.
So I wantAto send signal toBas soon as it finishes its initialization and enters its even loop.But, I don't have a way to send signal from
Aonce it got to its event loop,
(nor do I have a way to send signal fromBonce it entered its event loop),
nor do I have guarantees on which of the thread will get to its event loop first (and thus is ready to process signals)...
I could useQTimer::singleShotbut I'd like to avoid race.Is there a signal emitted when the event loop starts?
- main thread instantiates
-
When the two threads already exist when the first signal is emitted, I would expect that the signals get queued - do you have any problems with that?
Otherwise you can fire an own signal just right before you're starting the eventloops in the threads. -
When the two threads already exist when the first signal is emitted, I would expect that the signals get queued - do you have any problems with that?
Otherwise you can fire an own signal just right before you're starting the eventloops in the threads.@Christian-Ehrlicher said in "I am ready to receive Signals" signal:
When the two threads already exist when the first signal is emitted, I would expect that the signals get queued - do you have any problems with that?
No that I have problems with that, I just didn't think they will be queued, I thought they will get lost for sure, so I didn't try...
Will try and report.@Christian-Ehrlicher said in "I am ready to receive Signals" signal:
Otherwise you can fire an own signal just right before you're starting the eventloops in the threads.
That's the problem - I don't know when does the secondary thread starts its
run().
I know when it starts itsstart()(that's when thestartedsignal will be emitted), but not when itsrun()starts, and that's what important, becauserun()is the starting point of the thread. -
Events will not be lost. They will be queued for sure. Just check. Another point is you can emit signal from run method itslef.
-
Events will not be lost. They will be queued for sure. Just check. Another point is you can emit signal from run method itslef.
@dheerendra I'd have to subclass
QThreadfor that... -
Most closest is started signal. Run is called immediately after sending signal. Nothing in between.