【问题标题】:Can't read the output of the command when using QProcess使用 QProcess 时无法读取命令的输出
【发布时间】: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


    【解决方案1】:

    问题不在于 QProcess,而是因为在工具箱中运行 QProcess。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 2012-11-11
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多