Qt app stays in memory even after MainWindow is closed

坚强是说给别人听的谎言 提交于 2019-12-10 14:12:02

问题


The problem is as follows: if the application is closed while it's not actively doing anything, it exits correctly. If it's actively working on something (waiting in a while loop, for example), however, the main window will close but the program will continue to run in the background, as confirmed by opening the task manager.

I've spent a good part of today googling the problem and implementing possible fixes, but to no avail. It seems like the quit() function simply doesn't do anything. Here are some things that I've tried:

  • Using app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));. I know the signal is triggered, because I tried changing &app, SLOT(quit()) to qApp, SLOT(aboutQt()) and the aboutQt window briefly popped up.
  • Including qApp->quit(); at the beginning of a function that runs from a main window button. The application does run to that line, but it has no effect.
  • Using processEvents() to make sure the GUI is being updated.
  • Including statements like mainWindow.setAttribute(Qt::WA_QuitOnClose); in main.cpp.

I just want the application to completely exit when the main window is closed.

I'm using the qextserialport library, if that makes any difference.


回答1:


I don't know what's wrong, but as your slot actually receives the signal, you can call exit() from that slot function as a workaround.



来源:https://stackoverflow.com/questions/8826747/qt-app-stays-in-memory-even-after-mainwindow-is-closed

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