0
我想写一个测试程序。它将打开一个特殊的*.tests
文件并通过文件中的测试测试直接程序。Qt程序与壳牌
我需要:
- 运行某些程序。例如
./main -testing 45 563 67
- 听结果。
我该怎么办呢?我想通过一些测试运行程序main
,并听取其结果。
我想写一个测试程序。它将打开一个特殊的*.tests
文件并通过文件中的测试测试直接程序。Qt程序与壳牌
我需要:
./main -testing 45 563 67
我该怎么办呢?我想通过一些测试运行程序main
,并听取其结果。
你应该使用QProcess
类来启动你的程序。
QString program = "./main";
QStringList arguments;
arguments << "-testing" << "45" << "563" << ...;
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);
然后您可以使用waitForFinished
等待它完成。 exitCode
会给你返回码。
readAllStandardOutput
(或*Error
)方法允许您读取进程已输出到控制台的内容。
谢谢。但我有一个问题。 readAllStandardOutput返回QByteArray。如果程序将写入 - (7 \ n67 \ n78 \ n),什么格式将是qbytearray? – tucnak
它将具有完全相同的格式。你可以从QByteArray创建一个QString,或者从它创建一个QBuffer。 – Mat