QProcess* p = new QProcess;
p->setProgram("ping");
p->setArguments(QStringList()<<"127.0.0.1");
connect(p, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus){
qDebug()<<"finished";
});
connect(p, &QProcess::stateChanged,
[=](QProcess::ProcessState state){
qDebug()<<"stateChanged"<<state;
});
qDebug()<<p->startDetached();
qDebug()<<"startDetached";
as the above demo, I expect output finished
after ping is done. but it didn't, even stateChanged
didn't emit.
(BTW, I think I have plan B to implement this by using qtconcurrent)
https://doc.qt.io/qt-5/qprocess.html
QString hostName = "127.0.0.1";
proc = new QProcess();
connect(p, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus){
qDebug()<<"finished";
});
connect(p, &QProcess::stateChanged,
[=](QProcess::ProcessState state){
qDebug()<<"stateChanged"<<state;
});
proc->start("ping", QStringList() << QString(hostName));
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.