Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

"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 class B with different Thread affinity; A lives on the main thread, and B lives on a second thread.

    1. main thread instantiates B
    2. invokes moveToThread(secondThread) on B
    3. invokes secondThread->start()
    4. main thread instantiates A
    5. main thread will do connect(A, someSignal, B, someSlot)
    6. invokes QtApplication::exec()

    Now, A being a GUI and B being some module, I need A to obtain some data from B that is needed for A to display.
    So I want A to send signal to B 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 from B 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 use QTimer::singleShot but I'd like to avoid race.

    Is there a signal emitted when the event loop starts?


  • Qt Champions 2019

    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 its start() (that's when the started signal will be emitted), but not when its run() starts, and that's what important, because run() is the starting point of the thread.


  • Qt Champions 2017

    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...


  • Qt Champions 2017

    Most closest is started signal. Run is called immediately after sending signal. Nothing in between.


Log in to reply