signals sent by qtcreator on “stop”

穿精又带淫゛_ 提交于 2019-12-04 08:09:14

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:

Short version: You can't

Long version:

You could try using:

http://doc.qt.digia.com/qt/qcoreapplication.html#aboutToQuit

But this won't work as expected. If a process is terminated by force (which is what the stop in the IDE is doing, I'd guess using TerminateProcess() on windows http://msdn.microsoft.com/en-gb/library/windows/desktop/ms686714(v=vs.85).aspx ) then the process is instantly killed in the middle of whatever it is executing. Its not possible to handle these cases from Qt alone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!