0
votes

I do the following to start a process and waits for its completion (I am intentionally avoiding use of SIGNAL/SLOTS in this case).

QProcess *myProcess = new QProcess();
QString program = "test.exe";
QStringList args;
myProcess->start(program, args);
myProcess->waitForStarted();

while( myProcess->state() == QProcess::Running )
{
    // Do other things...
}

I can verify that test.exe exits. But process state is for some reason always QProcess::Running. I am using Qt 4.8.2 on Windows.

2

2 Answers

2
votes

If "do other things" does not include processing events of the thread's event loop, then the QProcess never gets a chance to update its state.

Either waitForFinished if this needs to block the thread or connect to the finished() signal.

0
votes

I don't think state() should be used to check for a program that has closed down but you can use something like while(!waitForFinished(1)).