QTimer make traitement out of for loop ?
-
Hi,
what i have to do to keep the traitement inside qtimer tirning without passing to the next if condition here ?for(..) { if(..){ QTimer::singleShot(6000, [=](){ qDebug()<<"Timer on do something after 6 second..."; // i want to set a time out condition here });//timer ends here }//end if else {..} }//end for
-
Hi,
Are you asking to block the code in that if block until the timer times out and the lambda is finished ?
-
When you want to make things clearer, you can simply edit your original thread message and add more information with a note stating what you added.
-
@imene said in QTimer make traitement out of for loop ?:
i will delete the other topic
And please do not do this! You had asked different questions there first, people had taken time to respond, and now you have deleted the whole topic. Once people at least respond in a topic please don't delete it; you can always mark it as Solved and raise a different topic for a different question.
-
Okay i restored it, i'm new at this Forum and i was little bit confused how to make a clear topic.
https://forum.qt.io/topic/138912/how-can-i-set-time-out-condition-in-the-timer
i'm sorry.. -
Based on you other thread, I would say that you should refactor your payload processing logic.
Rather than I tight loop that you are going to block use for example invokeMethod when you are done with the processing of the current payload. That way, for that particular case, you will call invokeMethod as the last thing in you lambda to continue the processing. Your loop will otherwise continue.
-
That's one way of implementing it.
-
@imene C++ lambda functions: https://en.cppreference.com/w/cpp/language/lambda
-
@imene said in QTimer make traitement out of for loop ?:
to make the traitement inside QTimer::singleShot before it pass to make the next if condition .
Let the QTimer::singleShot() fire and check for your codition inside the slot.
-
@Christian-Ehrlicher how ?
-
@imene said in QTimer make traitement out of for loop ?:
how ?
if (yourCoditionIsMet) { doSomethingYouWant() }
maybe?