The Qt documentation gives this explanation:
QProcess::start
:
Starts the given program in a new process, if none is already running, passing the command line arguments in arguments.
QProcess::startDetached
:
Starts the program program with the arguments arguments in a new process, and detaches from it.
What is the difference between the two? Is the difference only that you can start just one instance of a program using QProcess::start
and many instances using QProcess::startDetached
?
What it did, it actually created this QProcess subclass on the heap and used its ordinary start () method. In this mode however the signal, which fires once the process has finished, calles upon a slot which deletes the object itself: delete this;. It works.
1: it controls if the process you start is attached to your app (process) with start, if you close app, it will delete the started process also. with startDetached, you can close app and started process still lives on. https://stackoverflow. com/questions/23263805/what-is-the-difference-between-qprocessstart-and-qprocessstartdetached 2:
If you start a program using QProcess without detaching, then the destructor of QProcess will terminate the process. In contrast, a detached process keeps running unaffected when the calling process exits. On Unix, a detached process will run in its own session and act like a daemon.
The problem is that QProcess::startDetached () is a static method which creates a "fire and forget" process. This means, that you cannot set a working directory this way.
If you use start
, termination of the caller process will cause the termination of the called process as well. If you use startDetached
, after the caller is terminated, the child will continue to live. For example:
QProcess * p = new QProcess();
p->start("some-app");
delete p;// <---some-app will be terminated
QProcess * p = new QProcess();
p->startDetached("some-app");
delete p;// <---some-app will continue to live
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With