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();
source share