即使关闭MainWindow,Qt应用程序仍保留在内存中 [英] Qt app stays in memory even after MainWindow is closed

查看:573
本文介绍了即使关闭MainWindow,Qt应用程序仍保留在内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题如下:如果应用程序在不执行任何操作时关闭了,则它会正确退出.但是,如果它正在积极地工作(例如,在while循环中等待),则主窗口将关闭,但程序将继续在后台运行,这通过打开任务管理器来确认.

今天,我花了大量时间来探究问题并实施可能的修复,但无济于事.似乎quit()函数根本不执行任何操作.这是我尝试过的一些事情:

  • 使用app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));.我知道信号已触发,因为我尝试将&app, SLOT(quit())更改为qApp, SLOT(aboutQt())并短暂弹出aboutQt窗口.
  • 在从主窗口按钮运行的函数的开头包含qApp->quit();.该应用程序确实可以运行到该行,但是没有任何作用.
  • 使用processEvents()确保正在更新GUI.
  • 在main.cpp中包括类似mainWindow.setAttribute(Qt::WA_QuitOnClose);的语句.

我只希望应用程序在关闭主窗口时完全退出.

我正在使用qextserialport库,如果有什么不同的话.

解决方案

我不知道出了什么问题,但是当您的插槽实际接收到信号时,您可以从该插槽功能中调用exit()作为解决方法.

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.

解决方案

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.

这篇关于即使关闭MainWindow,Qt应用程序仍保留在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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