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. Question to QEventLoop
QtWS25 Last Chance

Question to QEventLoop

Scheduled Pinned Locked Moved Solved General and Desktop
qeventloop
3 Posts 2 Posters 674 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.
  • R Offline
    R Offline
    robro
    wrote on last edited by
    #1

    Hello,
    I got a question regarding a QEventLoop.

    What happens if a signal connected to a QEventLoop, which is not executed yet, is emitted?
    In my case I trigger a function in another thread with a signal and then I want to wait for a signal that the function emits when it is finished.
    Not I could imagine, that my function in another thread could maybe emit the signal before I called "loop.exec();"
    So is the signal even then already "stored" in my loop and automatically processed when calling "exec" or do I need to do something else to make sure that the signal is not lost?

    This is an example:

     QTimer timer;
        timer.setSingleShot(true);
        QEventLoop loop;
        connect(&worker,  SIGNAL(workInOtherThreadDone()), &loop, SLOT(quit()) );
        connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
        emit doSomethingInOtherThread(); //Triggers function in other thread which then emits "workInOtherThreadDone"
        timer.start(1000); 
        loop.exec();
        if(timer.isActive())
        {   
               //do something
        }
        else  qWarning("timeout!");
        
    

    Thank you very much :-)

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      So is the signal even then already "stored" in my loop and automatically processed when calling "exec"

      Short answer: yes.

      Explanation: since loop lives in a different thread from the one emitting the signal the execution of slots will be delayed untill control goes back to any event loop in the receiving thread. In your case this happens when you call loop.exec();

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • R Offline
        R Offline
        robro
        wrote on last edited by
        #3

        Thank you very much! :-)

        1 Reply Last reply
        0

        • Login

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