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
?
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
The start() function is a member function, while startDetached is a static class function.
If you look at the documentation of QProcess , you'll see that there are functions to allow you to do things with the process such as: -
These are just some of the things that you can only do with an instance of a QProcess. If, however, you want a simple and quick way of starting a process without having to create an instance and you don't need the extra functionality, you can simply call QProcess::startDetached.
Also, as the docs state for startDetached : -
If the calling process exits, the detached process will continue to live.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.