Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top