使用QProcess要注意的问题(QProcess::start: Process is already running)

问题:

今天在同一线程内多次使用QProcess调用mplayer播放视频,
每次调用完毕后都调用QProcess::terminate ()结束,但是线程下次循环调用QProcess出现错误:
“QProcess::start: Process is already running”

分析:

terminate()只是通知QProcess结束,但QProcess并没有马上结束;QProcess文档:http://developer.qt.nokia.com/doc/qt-4.8/qprocess.html

void QProcess::kill () [slot]

Kills the current process, causing it to exit immediately.

On Windows, kill() uses TerminateProcess, and on Unix and Mac OS X, the SIGKILL signal is sent to the process.

On Symbian, this function requires platform security capability PowerMgmt. If absent, the process will panic with KERN-EXEC 46.

Note: Killing running processes from other processes will typically cause a panic in Symbian due to platform security.

See also Symbian Platform Security Requirements and terminate().

void QProcess::terminate () [slot]

Attempts to terminate the process.

The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc).

On Windows, terminate() posts a WM_CLOSE message to all toplevel windows of the process and then to the main thread of the process itself. On Unix and Mac OS X the SIGTERM signal is sent.

Console applications on Windows that do not run an event loop, or whose event loop does not handle the WM_CLOSE message, can only be terminated by calling kill().

On Symbian, this function requires platform security capability PowerMgmt. If absent, the process will panic with KERN-EXEC 46.

Note: Terminating running processes from other processes will typically cause a panic in Symbian due to platform security.

See also Symbian Platform Security Requirements and kill().

结论:

如创建了一个线程   mplayerProcess = new QProcess(this);
使用线程打开另外一个程序  mplayerProcess->start(tr(paths, args);
当被调用的程序退出时,一定要加这个判断:

if(!mplayerProcess->waitForFinished(3000))

{......}

否则你再接着使用该线程时,可能会提示:QProcess::start: Process is already running 。


  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值