From dedd543a3440e769b98e2c181e03126347d94983 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Thu, 11 Jun 2026 19:48:19 +0800 Subject: [PATCH] fix(editor): fix window close logic and lambda capture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix window close timing by checking tabbar count instead of just wrappers. Use proper lambda capture [this] to avoid StartManager::instance() race condition. 修复窗口关闭时机判断,添加标签页计数检查。 修复lambda捕获问题,使用this指针避免instance()竞态条件。 Log: 修复窗口关闭逻辑 PMS: BUG-365421 Influence: 修复编辑器关闭时可能出现的窗口未正确关闭问题,提升应用稳定性。 --- src/startmanager.cpp | 4 ++-- src/widgets/window.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/startmanager.cpp b/src/startmanager.cpp index 90d84634..d663de78 100644 --- a/src/startmanager.cpp +++ b/src/startmanager.cpp @@ -805,8 +805,8 @@ void StartManager::slotCloseWindow() // 导致被附加到上一文本编辑器进程 QDBusConnection::sessionBus().unregisterService("com.deepin.Editor"); - QTimer::singleShot(1000, []() { - StartManager::instance()->delayMallocTrim(); + QTimer::singleShot(1000, [this]() { + this->delayMallocTrim(); QApplication::quit(); }); diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index 6ff212b3..ffd8c408 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -1199,8 +1199,10 @@ void Window::removeWrapper(const QString &filePath, bool isDelete) } } - // Exit window after close all tabs. - if (m_wrappers.isEmpty()) { + // Exit window after close all tabs (including pending and blank tabs). + // Pending tabs are kept in m_pendingTabs, blank tabs are managed by the tabbar. + // Only close the window when the tabbar has no tabs left. + if (m_wrappers.isEmpty() && m_tabbar->count() == 0) { close(); qInfo() << "after close"; }