【发布时间】:2015-07-28 21:22:13
【问题描述】:
在我的应用程序中,我有一个托盘图标,因此我覆盖了 closeEvent 以便应用程序在某些事情发生时“最小化”。但是,我确实希望在按下退出后,应用程序将完全退出。但是,在覆盖 closeEvent 并调用函数 quit() 之后,它似乎绕过了 MainWindow 析构函数,我在其中有一些代码。 我在 closeEvent 中缺少什么来正确关闭应用程序以便调用 MainWindow 的析构函数,就像没有覆盖 closeEvent 的情况一样?
我试过了
QMainWindow::closeEvent(event);
还有其他一些东西,但从不调用析构函数。
我的关闭事件实现是:
void MainWindow::closeEvent(QCloseEvent * event)
{
if(m_closeCompletely == false)
{
if (trayIcon->isVisible())
{
QMessageBox::information(this, tr("Hello"),
tr("The program will keep running in the "
"system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu "
"of the system tray entry."));
}
}
else
{
event->accept();
}
}
【问题讨论】:
-
你能显示更多上下文吗?你是如何实现
closeEvent()的?您是否尝试过文档中的示例? doc-snapshot.qt-project.org/4.8/qwidget.html#closeEvent