使用外部可执行文件作为管道的Qt 'way'是什么?

What is the Qt 'way' for using an external executable as a pipe?

本文关键字:way 是什么 Qt 外部 可执行文件 管道      更新时间:2023-10-16

我有一个使用Qt框架的GUI应用程序和另一个只处理stdin中的一些文本并在stdout中显示其输出的应用程序。

如何便携地使用Qt应用程序中的第二个可执行文件?主应用程序的用户将创建需要处理的数据。(结果将显示给用户)

第二个应用程序不能知道/依赖于主应用程序的任何内容,因此开发类似服务器的抽象是不可能的。

我不想为此编写Linux特定的代码,因为应用程序将来需要在其他平台上运行。

您可以使用QProcess启动第二个应用程序,提供输入并读取其输出:

QProcess process;
process.start("secondApp");
process.waitForStarted();
process.write(input, count);
process.closeWriteChannel();
process.waitForFinished();
QByteArray output;
output = process.readAllStandardOutput();