Solved Infinite condition checking
-
-
Hi,
Since foo checks the condition on each call, in fact, you want something that calls regularly foo ?
-
@SGaist something that calls condition regularly and if condition returns true then foo will be called
-
Sounds like a simple QTimer that calls foo regularly should do the job.
-
@SGaist That did solve my problem, thanks
void SomeClass::foo() { if( ! condition) { QTimer::singleShot(5000, this, &SomeClass::foo); return; } ... }
-
You might want to consider making a QTimer member variable to be able to stop it for example when your application ends.
-
@SGaist didn't quite understand what you meant, when my application won't everything be stopped?
Also, I need to call foo only once when the timeout is emitted, took that example from the documentation.
-
I don't know how long foo will take so you might not want for it to triggered when you end your application. Ending an application does not mean everything is destroyed instantly.
-
@SGaist foo is not from the mainwindow, is part of another class, should I call stop in the destructor?
-
@hbatalha said in Infinite condition checking:
is part of another class
Then put it there as member variable and stop it in destructor (or whenever needed).
-
@jsulm ok thanks
-
Ending an application does not mean everything is destroyed instantly.
I have followed your suggestion, and now I am wondering, is this something that I have to always watch out for, is there a name for this kind of situation, a reference I can search?
And also, why is everything not destroyed instantly? What are the steps being taken? What is happening under the hood there? Any reference?
-
Order of destruction, code run during destruction, etc
Think of a database, you likely appreciate the fact that all operations are finalised before it stops so you don't have corrupted data when you restart it.