Important: Please read the Qt Code of Conduct -

Pause loop until signal is emitted?

  • Hello!

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

    @QStringList list;





    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!

  • Lifetime Qt Champion

    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

  • 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

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

  • Lifetime Qt Champion

    What are you trying to achieve exactly ?

Log in to reply