Disabling an initiated process

I started the process using QProcess::start() , and I need to separate it later. How can I do it? I did not find the relevant information in the Qt docs.

I know QProcess::startDetached() , but due to different code in the program, I cannot use it (I need to separate the start and shutdown of the process).

+4
source share
2 answers

You cannot with 5.1, see here . There's also a suggestion in the comments, not sure what is useful for your case):

Workaround: Write a helper process that starts the disconnected processes and ends when all settings are complete.

+4
source

If you look at the implementation of QProcess::~QProcess() , you will learn how QProcess ends the process with its destruction. Also note that QProcess::setProcessState() is protected , which means that you can implement the QDetachableProcess inherited from QProcess using the detach() method before calling setProcessState(QProcess::NotRunning); as a workaround.

For instance:

 class QDetachableProcess : public QProcess { public: QDetachableProcess(QObject *parent = 0) : QProcess(parent){} void detach() { this->waitForStarted(); setProcessState(QProcess::NotRunning); } }; 

Then you can do things like this:

 QDetachableProcess process; process.setEnvironment(QStringList() << "SOME_ENV=Value"); process.start(); process.detach(); 
+6
source

Source: https://habr.com/ru/post/1490024/


All Articles