简体   繁体   English

退出 Qt 应用程序不会杀死生成的线程

[英]Exiting Qt application does not kill spawned threads

I have a Qt program that is using the QtConcurrent API to spawn worker threads.我有一个 Qt 程序,它使用 QtConcurrent API 来生成工作线程。 The problem I am having is that the worker threads keep going even if I exit the Qt application.我遇到的问题是,即使我退出 Qt 应用程序,工作线程也会继续运行。

I have an actionExit in my menu, which is what i am using to close the app, or the "X" in the window corner.我的菜单中有一个 actionExit,这是我用来关闭应用程序的,或者是 window 角落中的“X”。 Is there any way to make these kill off all threads related to this app?有没有办法让这些杀死与这个应用程序相关的所有线程?

Thanks谢谢

Are you sure that the UI application really closes?您确定 UI 应用程序真的关闭了吗? You might be missing:你可能会错过:

qApp->setQuitOnLastWindowClosed(true);

Otherwise QT only hides your window.否则 QT 只会隐藏您的 window。 To debug put a breakpoint behind your mainWindow->exec();要调试,请在mainWindow->exec(); and see whether it is really reached.看看是否真的达到了。

If you confirm that exec() returns and QTConcurrent really hangs (it might be possible: http://lists.trolltech.com/qt-interest/2008-06/thread00414-0.html ), then do:如果您确认 exec() 返回并且 QTConcurrent 确实挂起(可能: http://lists.trolltech.com/qt-interest/2008-06/thread00414-0.html ),然后执行:

exit(0);

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

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