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. Pause loop until signal is emitted?
Forum Update on Monday, May 27th 2025

Pause loop until signal is emitted?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.2k 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.
  • H Offline
    H Offline
    HennsWoerst
    wrote on last edited by
    #1

    Hello!

    I would like to achieve the following (it's very simplified):

    @QStringList list;

    MethodA(){

    while(elementsInList){
    
        MethodB(nextElement);
        waitUntilMethodBIsFinished;
        readGlobalVariable;
        proceedWithLoop;
    }
    

    }

    MethodB(nextElement){

    doBusinessWithElement;
    setGlobalVariableWithResultOfBusiness;
    emit signal(finished)
    

    }
    @

    I read that this could maybe be realized with a QEventLoop (?) but it is not recommended due to stability issues? What would you recommend?

    Thank you!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Your simplified example does already what you want since MethodB will only return when it ended.

      You should maybe show something (even if a bit more complex) that shows what you currently want to realize

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NicuPopescu
        wrote on last edited by
        #3

        check QThread and QWaitCondition

        QThread has a local event loop, started by exec() but it is for cases when you need to receive events within thread ... in most cases you need to run a "non event" loop (while,forever etc.) with conditions

        1 Reply Last reply
        0
        • H Offline
          H Offline
          HennsWoerst
          wrote on last edited by
          #4

          Thank you for your answers! I suppose you're right, I should have been more specific... MethodB is a slot waiting for a webframe to load

          @
          page.mainFrame()->load(QUrl(url + nextString));
          QWebFrame *frame = page.mainFrame();
          connect(frame, SIGNAL(loadFinished(bool)),this, SLOT(MethodB(bool)));
          @

          while this works fine with only one string it fails in the loop because the load method gets called far too frequently, so I thought of stopping the loop until the frame retrieves the data from the web, performs it's business with it and then emits a finished signal so that the loop can pass the next string...

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What are you trying to achieve exactly ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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