"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
A
and classB
with different Thread affinity;A
lives on the main thread, andB
lives 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,
A
being a GUI andB
being some module, I needA
to obtain some data fromB
that is needed forA
to display.
So I wantA
to send signal toB
as soon as it finishes its initialization and enters its even loop.But, I don't have a way to send signal from
A
once it got to its event loop,
(nor do I have a way to send signal fromB
once 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::singleShot
but 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. -
@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 thestarted
signal 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.
-
@dheerendra I'd have to subclass
QThread
for that... -
Most closest is started signal. Run is called immediately after sending signal. Nothing in between.