qtcreator在“停止"时发送的信号 [英] signals sent by qtcreator on "stop"

查看:522
本文介绍了qtcreator在“停止"时发送的信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux上工作,当我使用Qt Creator IDE上的停止"按钮将其关闭时,我意识到我的应用程序正在离开守护进程.我想处理这些情况,因此应用程序的关闭方式与关闭主窗口时的关闭方式相同.要编写处理程序,我需要知道它对应于哪些信号.

解决方案

深入到QtCreator的代码中,我可以看到QtCreator在内部使用QProcess来启动您的应用程序.红色的停止"按钮连接到ApplicationLauncher::stop(),这将以两种方式之一终止您的进程,具体取决于它是GUI应用程序还是控制台应用程序,但是在两种情况下,结果最终在Linux上都是相同的. /p>

对于GUI应用程序,ApplicationLauncher调用QProcess::terminate(),这又将SIGTERM(在Linux上)信号发送到守护程序.然后,它等待(使用waitForFinished())1秒钟,如果到那时守护进程尚未退出,它将调用QProcess::kill(),发送SIGKILL.

对于控制台应用程序,ApplicationLauncher将终结点委托给ConsoleProcess实用工具类.在Linux上,对于GUI应用程序,ConsoleProcess::stop()的作用类似于ApplicationLauncher,它首先发送SIGTERM,然后等待1秒钟,然后发送SIGKILL(如果尚未终止).

您将在QtCreator中找到相关代码:

I am working on linux and I realized that my application was leaving behind daemon processes when I close it with the "Stop" button on Qt creator IDE. I want to handle these cases so the application close the same way as when I close the main window. To write the handlers, I need to know which signals it corresponds to.

解决方案

Digging into QtCreator's code, I can see that QtCreator uses a QProcess internally to launch your app. The red "stop" button is connected to ApplicationLauncher::stop(), which terminates your process in one of two ways depending if it's a GUI app or a console app, but in both cases, the result end up to be the same on Linux.

For a GUI app, ApplicationLauncher calls QProcess::terminate(), which in turn sends a SIGTERM (on Linux) signal to your daemon. It then waits (with waitForFinished()) for 1 second, and if the daemon hasn't quit by then, it calls QProcess::kill(), sending SIGKILL.

For a console app, ApplicationLauncher delegates the termination to the ConsoleProcess utility class. On Linux, ConsoleProcess::stop() will act similar to ApplicationLauncher for a GUI app, which is first sending SIGTERM, then waiting for 1 second, and sending SIGKILL if it hasn't terminated yet.

You will find the relevant code from QtCreator here:

这篇关于qtcreator在“停止"时发送的信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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