WaitForFinished() fires early



  • 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();
    @



  • On which platform do you use it?
    are you sure, the process is started?



  • 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.



  • 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....



  • 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.



  • Have you tried calling waitForStarted() before calling waitForFinished()?



  • 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.



  • 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.



  • 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);
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.