使用 QProcess 时无法读取命令的输出
Can't read the output of the command when using QProcess
我的程序需要发送带有 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,而是因为工具箱中的 运行 QProcess。
我的程序需要发送带有 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,而是因为工具箱中的 运行 QProcess。