altairwei / WizNotePlus

A community-driven cross-platform note-taking client.

Home Page:https://altairwei.github.io/WizNotePlus/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] 打开消息控制台后关闭主窗口再关闭消息控制台导致程序退出

notplus opened this issue · comments

打开消息控制台后,关闭主窗口,再关闭消息控制台会产生lastWindowClosed信号,导致程序退出,算是一个小bug

任何非模态对话框都会导致这个问题。

下面这行代码估计是历史遗留问题,但没有明确指出是哪个 Qt Bug 。

#ifndef Q_OS_MAC
    connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit())); // Qt bug: Qt5 bug
#endif

我没有想到一个将 lastWindowClosed 与 quit 连接到一起的理由。一个可能的猜测是:当用户不使用系统托盘图标时,他期望的行为可能就是 “窗口关闭 -> 应用退出” 。

但奇怪的是,直接删除掉这段代码无法解决这个 BUG 。

我检查了下,问题不是 lastWindowClosed 信号,而是 aboutToQuit 信号。

lastWindowClosed 确实会激发,但 aboutToQuit 在它之前就被激发了。

我在 Qt 文档中发现了这个,原来如此:

quitOnLastWindowClosed : bool
This property holds whether the application implicitly quits when the last window is closed.
The default is true.
If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) is closed.

现在 WizNotePlus 预期的行为模式是这样的:

  1. 当使用 SystemTrayIcon 时,QMainWindow 不会被关闭只会被隐藏。任何其他窗口的关闭都不会引起应用程序的退出。应用程序的退出要求用户显示操作。
  2. 当不使用 SystemTrayIcon 时,最后一个可见窗口的关闭才会引起应用程序的退出。