Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between QProcess::start and QProcess::startDetached?

Tags:

c++

qt

qprocess

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?

like image 751
Nejat Avatar asked Apr 24 '14 08:04

Nejat


People also ask

How does qprocess start () work?

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.

What is the difference between qprocessstart and startdetached?

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:

What is the difference between a detached process and qprocess?

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.

Why can't I set a working directory in qprocess?

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.


1 Answers

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
like image 169
SingerOfTheFall Avatar answered Sep 19 '22 12:09

SingerOfTheFall