WaitForFinished() fires early
-
wrote on 30 Jun 2011, 12:15 last edited by
Hi guys,
so im starting a process (which i actually have not coded myself - but still i have to use it) via a QProcess and want to see if it is finished - sure thats done like below (i think). This process is an optimization algorithm and it seems to fire the signal that it is done to my QtApp before the optimization progress even starts. You have any idea of fixing that (recall i cant change the code of the optimization app)?
@
QProcess *process;
process = new QProcess( this );process->start("myOptimizationApp");
process->waitForFinished();
@ -
wrote on 30 Jun 2011, 12:55 last edited by
On which platform do you use it?
are you sure, the process is started? -
wrote on 30 Jun 2011, 12:58 last edited by
The system is OpenSUSE x64.
The process is started, I'm sure because it has a GUI itself (and it opens) and waitForFinished() seems to wait for something because when it starts it will wait like 30secs into the program till it thinks about just leaving me in the rain - in contrast to this, if I leave out waitForFinished() it just continues with the routine in my QtApp right away.
-
wrote on 30 Jun 2011, 13:20 last edited by
I'm not sure how it is on Linux, but on windows, this wait AFAIK only works correct for command line processes, not for UI processes....
-
wrote on 30 Jun 2011, 13:32 last edited by
Okay if you say so. I'm sure there is a way to get things right with a little linux hacking. It might work if you have a bashscript checking for the process running and keep it in an while-loop. I'll post the workaround here if I've figured it out.
-
wrote on 1 Jul 2011, 06:48 last edited by
Have you tried calling waitForStarted() before calling waitForFinished()?
-
wrote on 1 Jul 2011, 08:17 last edited by
I recommend you to use QEventLoop. With this way, your main program won't sleep until process finishes. It'll be still usable. Sth like that:
@
QEventLoop waitLoop;
connect(process, SIGNAL(finished(int, QProcess::ExitStatus),
&waitLoop, SLOT(quit()));
process->start();
waitLoop.exec();
@I use this sometimes.
-
wrote on 1 Jul 2011, 10:48 last edited by
waitForFinished() has a time out parameter which specifies the maximum amount of time it will wait before returning, the default value is 30000 milliseconds. If you pass a value of -1 instead it will never time out.
-
wrote on 4 Jul 2011, 06:40 last edited by
Thanks guys. Andrew you plucked the right nerve as the program itself need a lot of time to start and optimize. When setting the value to -1 it will wait till the program really exits. The final solution for everyone:
@
QProcess *process;
process = new QProcess( this );process->start("myOptimizationApp");
process->waitForFinished(-1);
@
6/9