Suppose I start a process in terminal in Linux, if the terminal is closed the child process started in terminal also exits (even if process is started using sudo). But if I start a process (say) p1
using QProcess
inside a GUI
application, and then close the gui
application, process p1
still keeps running, as if it is a daemon, even if I don't start the process using QProcess::startDetached()
.
process1->start("gksudo",args);
and
process1->terminate();
process1->close();
in closeEvent.
Try adding
delete process1;
in GUI class destructor.
How are you initializing your QProcess? When I did the following (on Windows) in mainwindow.cpp
my child process closed when I closed my main application.
QProcess* proc = new QProcess(this);
proc->start("notepad.exe q:/blah2.txt");
By making MainWindow a parent of QProcess, MainWindow will destroy and close it during its QObject destructor.
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.