启动/运行外部可执行文件并查看其输出日志

时间:2018-12-31 09:46:39

标签: c++ qt logging qprocess

我从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 *上运行良好,但是问题是我看不到它的输出日志。有没有办法查看其日志?

1 个答案:

答案 0 :(得分:2)

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

相关问题