Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "I am ready to receive Signals" signal

"I am ready to receive Signals" signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 699 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Absurd
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        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.

        A Offline
        A Offline
        Absurd
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          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
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          A 1 Reply Last reply
          0
          • dheerendraD dheerendra

            Events will not be lost. They will be queued for sure. Just check. Another point is you can emit signal from run method itslef.

            A Offline
            A Offline
            Absurd
            wrote on last edited by
            #5

            @dheerendra I'd have to subclass QThread for that...

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

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

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved