You didn't write what You do in the loop's so I can't comment about crashes, well except if You use recursion then there is a limitation how many iteration can be rune before You crash (for my code It was around 9k or so).
As for the loops I do it with the QTimer::singleshot() approach, something like this:
void myClassBasedOnQObject::doSomeWork()
{
if (isDone) {
emit isDone();
return;
}
// do work here
QTimer::singleShot(0,
this,
SLOT(doSomeWork
()));
}
void myClassBasedOnQObject::doSomeWork()
{
if (isDone) {
emit isDone();
return;
}
// do work here
QTimer::singleShot(0, this, SLOT(doSomeWork()));
}
To copy to clipboard, switch view to plain text mode
It allows application to normally process main event loop, of course if Your task in doSomeWork() will take more time then You will notice GUI hangs, if so then use QThreads.
Bookmarks