简体   繁体   English

如果程序完成,QProcess exe不会关闭

[英]QProcess exe does not close if program finished

My problem is that I am starting an executable in a QProcess like the following: 我的问题是我正在QProcess中启动可执行文件,如下所示:

QProcess Work;
Work.start(program.exe);

This executable runs since it has been started in background and I can send requests to it. 由于该可执行文件已在后台启动,因此可以运行,我可以向其发送请求。 If I have finished I am closing the executable the following way: 如果完成,则按以下方式关闭可执行文件:

Work.close();

But if I am looking at the Taskmanager the program.exe is running furthermore. 但是,如果我正在查看Taskmanager,则program.exe会进一步运行。 I dont understand that behaviour because I thought the executable would been stopped if I close the Process. 我不了解这种行为,因为我认为如果关闭进程,可执行文件将被停止。

You should use void QProcess::terminate() or void QProcess::kill() for it. 您应该为此使用void QProcess :: terminate()void QProcess :: kill()

terminate() - attempts to terminate the process. terminate() -尝试终止进程。

kill() - kills process immediately. kill() -立即终止进程。

I had a very similar case, although I was working on linux embedded with QT 4.8. 我有一个非常相似的案例,尽管我正在使用QT 4.8嵌入式Linux。 Not sure if this can help you, but since I can't put it in a comment, I have to make a separate answer. 不确定这是否能为您提供帮助,但是由于我无法在评论中添加评论,因此我必须单独回答。

Do you set a parent to your QProcess? 您是否为QProcess设置了父母? In my case, I instantiated QProcess like this 就我而言,我像这样实例化了QProcess

QProcess *p = new QProcess;

and I could see in the running processes list that each time I instantiated a new QProcess, I got a new process that couldn't be closed by close() , terminate() or kill() . 而且我可以在运行的进程列表中看到,每次实例化一个新的QProcess时,都会得到一个新的进程,该进程无法通过close()Terminate()kill() 关闭 When I finally rewrote the code like this 当我终于重写了这样的代码

QProcess *p = new QProcess(mainW); //mainW was my GUI class, which handled also the closing of the process

the problem solved itself, I didn't even need to call any function to close the process. 问题解决了,我什至不需要调用任何函数来关闭进程。 In my case I was sure the processes I called were finishing, since almost all of them were audio files, so I could hear them finishing. 以我为例,我确定我调用的过程正在完成,因为几乎所有过程都是音频文件,因此我可以听到它们正在完成。 The others were processes that my program waited to complete, so again I was sure they ended because my program wasn't stuck waiting for them, 其他的是我的程序等待完成的进程,所以我再次确定它们已结束,因为我的程序没有等待他们的到来,

Hope this can help, despite the different OS. 希望尽管操作系统有所不同也能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM