简体   繁体   English

QProcess:启动子进程,而无需等待完成但获得完成信号

[英]QProcess: start child process without waiting for finishing it but getting finished signal

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? 如何在QT应用程序中使用QProcess启动外部子进程,并继续执行主程序,而不必等待子进程完成,但是同时,在以下情况下从子进程获取回调:他完成了吗?

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. 这里启动了子进程,主应用程序继续执行,但是尽管信号/插槽连接已完成,没有任何QT错误,但子进程完成时没有回调。

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? 有任何想法吗?

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. 故障发生在while / true块中,在第一种情况下这是无止境的,因此无法正确执行qt应用程序主事件循环中的信号/插槽处理。

Hint: Solution for us was to use a qthread for handling every external qprocess. 提示:我们的解决方案是使用qthread处理每个外部qprocess。 Think on mutexes where it is necessary. 在必要时考虑互斥量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM