This is the code to execute a command and return the output. The problem is that if I kill the testProcess, "ping" keeps on going. I tried also with
QObject *parent;
parent=new QObject;
myprocess *p;
p=new myprocess(parent);
sorry for my english
testProcess.h:
class myprocess : public QProcess{
Q_OBJECT
public:
myprocess( QObject *parent = 0 );
protected slots:
void readyOut();
void readyErr();
};
testProcess.cpp main:
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;
If you want your process to close when the application closes then you could connect to the core application aboutToQuit()
signal. It would look something like this
connect( QCoreApplication::instance(), SIGNAL(aboutToQuit()), p, SLOT(kill()));
There is also a terminate()
slot in the process that could be used, but I think kill()
may be more appropriate in your situation.
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.