QProcess 不发出完成信号
QProcess doesn't emit finish signal
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";
如上面的演示,我希望 ping 完成后输出 finished
。
但它没有,甚至 stateChanged
也没有发射。
(顺便说一句,我想我有计划 B 通过使用 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));
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";
如上面的演示,我希望 ping 完成后输出 finished
。
但它没有,甚至 stateChanged
也没有发射。
(顺便说一句,我想我有计划 B 通过使用 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));