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

Nejat picture Nejat · Apr 24, 2014 · Viewed 12.9k times · Source

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?

Answer

SingerOfTheFall picture SingerOfTheFall · Apr 24, 2014

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