[英]Process started with QProcess doesn’t exit if we close the main application
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). 假设我在Linux的终端中启动了一个进程,如果终端关闭,则在终端中启动的子进程也会退出(即使使用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()
. 但是,如果我在GUI
应用程序中使用QProcess
启动进程(例如) p1
,然后关闭gui
应用程序,则即使我不使用QProcess::startDetached()
启动进程,进程p1
仍保持运行,就好像它是守护程序一样QProcess::startDetached()
。
process1->start("gksudo",args);
and 和
process1->terminate();
process1->close();
in closeEvent. 在closeEvent中。
Try adding 尝试添加
delete process1;
in GUI class destructor. 在GUI类析构函数中。
How are you initializing your QProcess? 您如何初始化QProcess? When I did the following (on Windows) in mainwindow.cpp
my child process closed when I closed my main application. 当我在mainwindow.cpp
执行以下操作(在Windows上)时,关闭主应用程序时,我的子进程关闭了。
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. 通过使MainWindow成为QProcess的父级,MainWindow将在其QObject析构函数期间销毁并关闭它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.