[英]kill qprocess with parent
这是执行命令并返回输出的代码。 问题是,如果我终止了testProcess,“ ping”将继续进行。 我也尝试过
QObject *parent;
parent=new QObject;
myprocess *p;
p=new myprocess(parent);
对不起我的英语不好
testProcess.h:
class myprocess : public QProcess{
Q_OBJECT
public:
myprocess( QObject *parent = 0 );
protected slots:
void readyOut();
void readyErr();
};
testProcess.cpp主要:
myprocess *p;
p=new myprocess;
QObject::connect(p,SIGNAL(readyReadStandardOutput()),p,SLOT(readyOut()));
QObject::connect(p,SIGNAL(readyReadStandardError()),p,SLOT(readyErr()));
p->start("ping -t www.google.com");
p->waitForFinished(60000);
delete p;
如果要在应用程序关闭时关闭进程,则可以连接到核心应用程序aboutToQuit()
信号。 看起来像这样
connect( QCoreApplication::instance(), SIGNAL(aboutToQuit()), p, SLOT(kill()));
进程中还有一个terminate()
插槽可以使用,但我认为kill()
可能更适合您的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.