【发布时间】:2019-08-15 04:03:12
【问题描述】:
我是qt的初学者。如果这个问题解决了,那将非常有帮助。 我想使用 QProcess 来执行文件并将实时输出显示到 QTextviewer。 除非您在终端命令行中按 ctrl c,否则该文件无法停止运行。否则,该文件在 linux 的终端上运行良好。 出现的主要问题是:进程确实由 qt 启动,但是,我没有看到任何输出。
我尝试使用信号(readyReadStandardOutput)和插槽。当我添加 waitforfinished() 时,GUI 将冻结。
if(!process)
{
process = new QProcess (this);
}
process -> setWorkingDirectory("mydir");
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(logRead()));
connect(process, SIGNAL(readyReadStandardError()), this, SLOT(readError()));
process -> start("./file");
process -> setProcessChannelMode(QProcess::MergedChannels);
if(false == peocess-> waitForStarted())
{
ui -> textBrowser->append("the process cannot be called");
}else{
ui -> textBrowser->append("the process can be called");
}
textBrowser 确实显示“可以调用该进程”。
void Dialog::logRead()
{
QProcess *process = dynamic_cast<QProcess *>( sender() );
if (process){
ui->textBrowser->append( p->readAllStandardOutput() );
}
我不知道为什么我不能实时输出文本,即使我没有得到任何输出!!有什么建议吗?谢谢!
【问题讨论】:
-
离题但...来自
QProcess::setProcessChannelMode:"This mode will be used the next time start() is called"。所以在start之后调用setProcessChannelMode可能不会有预期的效果。