【发布时间】:2021-03-19 08:13:09
【问题描述】:
我的程序需要发送一个带有 QProcess 的命令行并检索结果,然后将显示在 GUI 中。
我要执行并读取其输出的命令是ostree remote refs kinoite
这是我的代码:
QProcess* process = new QProcess();
connect(process,&QProcess::readyReadStandardError,[process]() {
qWarning()<<"Error: " << process->readAllStandardError();
});
//catch data output
connect(process,&QProcess::readyReadStandardOutput,[process]() {
qWarning()<<"Output: " << process->readAllStandardOutput();
});
// delete process instance when done, and get the exit status to handle errors.
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus){
qWarning()<< "process exited with code " << exitCode;
process->deleteLater();
});
process->setWorkingDirectory(QStringLiteral("~"));
process->start(QStringLiteral("ostree"), {QStringLiteral("remote"), QStringLiteral("refs"), QStringLiteral("kinoite")});
没有收到信号,所以使用qWarning()时终端什么也没有显示
请提供任何帮助。
谢谢
【问题讨论】:
标签: qprocess