QProcess 和 shell:进程仍在运行时被销毁 [英] QProcess and shell : Destroyed while process is still running

查看:220
本文介绍了QProcess 和 shell:进程仍在运行时被销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 Qt 启动一个 shell 脚本.

I want to launch a shell script with Qt.

QProcess process;
process.start(commandLine, QStringList() << confFile);
process.waitForFinished();

if(process.exitCode()!=0)
{
    qDebug () << " Error " << process.exitCode() << process.readAllStrandardError();
}
else
{
    qDebug () << " Ok " << process.readAllStrandardOutput() << process.readAllStrandardError();
}

结果是:

好的 : 结果.... " "" QProcess : 进程仍然存在时被销毁运行.

Ok : Result.... " "" QProcess : Destroyed while process is still running.

此消息并非每次都出现.

This message does not appear every time.

有什么问题?

推荐答案

process.waitForFinished(); 达到了默认的 30 秒超时.使用 process.waitForFinished(-1); 代替.这将确保您等待该过程完成所需的时间,而不会出现任何超时.

process.waitForFinished(); is hitting the default 30 seconds timeout. Use process.waitForFinished(-1); instead. This will make sure you wait for however long it takes for the process to finish, without any timeout.

这篇关于QProcess 和 shell:进程仍在运行时被销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆