按照您说的方法 我禁用了stdout的缓冲区 但是还是达不到我想要的效果
依旧是只有当printf输出的数据达到了一定程度,readallstandout()才会读到东西
下面是代码片段
//启动了个定时器 每200ms调用freshUI();
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(freshUI()));
timer->start(200);
//读取标准输出追加到界面上
QString outputText = process->readAllStandardOutput(); //读取标准输出
if(outputText.simplified()!= "")
{
saveToText(outputText); //标准输出追加保存到文本中
ui.teLog->append(outputText); //界面上显示标准输出
}
//启动进程 禁用缓冲区(不知道具体加到哪里,所以前后都加了)
setvbuf(stdout, (char *)NULL, _IONBF, 0);
if(perlFileName.endsWith(".EXE")||perlFileName.endsWith(".exe"))
process->start(perlFileName); //运行perl脚本
else
//解决参数中路径存在空格的问题
process->start("perl.exe",QStringList()<<perlFileName); //运行perl脚本
setvbuf(stdout, (char *)NULL, _IONBF, 0);