【问题标题】:To start/run an external executable and see its output logs启动/运行外部可执行文件并查看其输出日志
【发布时间】:2018-12-31 09:46:38
【问题描述】:

我在我的 Qt 应用程序中运行一个名为 agent.exe 的外部可执行文件,如下所示:

// header
QProcess *m_agent;

// source
m_agent = new QProcess(this);

QString agentPath = QCoreApplication::applicationDirPath() + "/agent.exe";

if (QFileInfo::exists(agentPath) && QFileInfo(agentPath).isFile()) {
    m_agent->start(agentPath);
} else {
    qDebug() << __func__ << "Executable does NOT exist\n";
}

我的agent.exeQProcess * 上运行良好,但问题是我看不到它的输出日志。有没有办法查看它的日志?

【问题讨论】:

  • 输出日志是什么意思?您是指控制台输出还是 .log 文件?
  • @Gurushant 是的,我的意思是控制台输出

标签: c++ qt logging qprocess


【解决方案1】:

您可以将信号 readyReadStandardOutput()QProcess 连接到应用程序中的插槽并使用函数 QProcess::readAllStandardOutput() 您将获得 QByteArray 形式的数据,您可以将其保存在 QFile 或显示到QTextBrowser中的用户

【讨论】:

  • 谢谢,我要试试你的解决方案……让我试试
猜你喜欢
  • 2012-01-26
  • 2016-05-15
  • 2019-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-05
  • 2021-12-02
  • 1970-01-01
相关资源
最近更新 更多