PDA

View Full Version : For loop and While loop handling.



kiboi
19th December 2012, 05:47
Hi!

Im have a problem in handling the For loop and While loop. I put the While loop inside the For loop. Inside the For loop and While loop, i inserted the qApp->processEvents for me to be able to interact with the UI while the loop is on-going process. But i encounter cases that the application crashes while doing the process. is there any better approach for this? when i ran the application with qt environment, it doesn't crash but if i ran the application w/out qt, several times it crashes yet few times it doesn't. It seems its not stable.

Pls send your inputs guys!

Thanks!

Talei
19th December 2012, 08:34
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()));
}

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.

wysota
19th December 2012, 10:44
Here is an article to read too: Keeping the GUI Responsive

kiboi
20th December 2012, 03:58
Thanks guys for the inputs. I took the details of the cause of the crash. It points out: APPCRASH Cause of crash: ntdll.dll. Do you have any idea regarding this dll?

Santosh Reddy
20th December 2012, 07:53
when i ran the application with qt environment, it doesn't crash but if i ran the application w/out qt
What do you mean by "qt environment" and "w/out qt". I am wondering how can you use qApp->processEvents with out "qt environment"

amleto
20th December 2012, 15:10
Thanks guys for the inputs. I took the details of the cause of the crash. It points out: APPCRASH Cause of crash: ntdll.dll. Do you have any idea regarding this dll?

you dont need to worry about that! that is not the problem!

kiboi
2nd January 2013, 05:20
hi santosh,
With "qt environment" means the host pc has an installed qt creator while "w/out qt" means the pc doesn't have a qt creator. I'm pointing this out since I have created an installer and ran the exe without using the qt.

wysota
2nd January 2013, 13:43
I'm pointing this out since I have created an installer and ran the exe without using the qt.
If your application requires Qt then you can't run it without Qt. You need to deploy Qt dlls along with your application.