c++ - 如何捕获 QSystemTrayIcon 退出事件?

标签 c++ qt

我有一个QSystemTrayIcon子类。在里面,我有:

quitAction = new QAction(tr("&Quit"), m_parent);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); 

CloseEvent 在这里不起作用。我怎样才能捕获这个退出事件?我想在关闭之前保存数据。

最佳答案

您应该将清理/保存代码连接到 QCoreApplication::aboutToQuit()信号。

This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session.

关于c++ - 如何捕获 QSystemTrayIcon 退出事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6889368/

相关文章:

c++ - ^= 32 背后的想法是什么,它将小写字母转换为大写字母,反之亦然?

python - 在 C++ 中创建共享库以与 Python 集成

qt - 是否可以使现有图标在悬停时变亮

带有 VS2012 编译器的 Qt 5.1 - 代码 128 错误

c++ - QT中的多个连接对象

c++ - Qt构建错误: "WARNING: TARGET is empty" and "make: nothing to be done for "first""

c++ - Unordered_map 使用指针地址作为键

c++ - 如何将 boost::object_pool<>::construct 与非 const 引用一起用作 ctor 参数?

c++ - Qt 似乎使用了很多线程

python - 如何使用 PyQt4.QtWebKit 从选项列表中选择值