1
votes

How is it possible to start external child processes with QProcess in a QT Application, and go on with execution of the main program, without waiting for the child process to be finished, but in the same time, get an callback from the child process when he is done?

First Scenario:

QProcess* child = new QProcess();
connect(child, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(isFinished( int, QProcess::ExitStatus )));
child->start( "example.exe", QStringList() << path);
.
.
. further execution of main application

Here the child process is started and the main app goes on with execution, but although the signal/slot connection is done without any QT errors, there comes no callback when the child is finished.

Second Scenario:

QProcess* child = new QProcess();
connect(child, SIGNAL(finished(int, QProcess::ExitStatus)), this,       SLOT(isFinished( int, QProcess::ExitStatus )));
child->start( "example.exe", QStringList() << path);
child->waitForFinished();
.
.
. NO further execution of main application

Here the child process is started and the main app goes not on with execution, and the finished callback from signal/slot comes correctly. Both are not what i want.

Any ideas?

1
It's strange, the first scenario should work well. See demos\embedded\fluidlauncher\demoapplication.cpp and demos\qtdemo\menumanager.cpp in qt4.8 directory, I don't see a difference between your code and Qt samples. - Bogdan
First scenario works fine for us and would be the correct implementation. - Sebastian Lange
May be this object gets deleted before the process was finished? - Pavel Strakhov

1 Answers

0
votes

The failure was in a while/true block that was endless in the first scenario and so the signal/slot handling in the main event loop of the qt app could not be done right.

Hint: Solution for us was to use a qthread for handling every external qprocess. Think on mutexes where it is necessary.