2023-06-05 15:50:19 +08:00
|
|
|
|
From 60547666dc4cafad4d65485c9830ced06a2e4d15 Mon Sep 17 00:00:00 2001
|
2022-11-25 11:04:29 +08:00
|
|
|
|
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
2023-06-05 15:50:19 +08:00
|
|
|
|
Date: Tue, 8 Nov 2022 16:37:10 +0800
|
|
|
|
|
|
Subject: [PATCH 1/4] fix(Memory leak): Fix the memory leak of allocating
|
|
|
|
|
|
QPalette when switching themes
|
2022-11-25 11:04:29 +08:00
|
|
|
|
MIME-Version: 1.0
|
|
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
|
|
|
|
修复切换主题时分配QPalette的内存泄漏
|
|
|
|
|
|
---
|
|
|
|
|
|
platformtheme/kiran-theme.cpp | 8 ++++++++
|
2023-06-05 15:50:19 +08:00
|
|
|
|
1 file changed, 8 insertions(+)
|
2022-11-25 11:04:29 +08:00
|
|
|
|
|
|
|
|
|
|
diff --git a/platformtheme/kiran-theme.cpp b/platformtheme/kiran-theme.cpp
|
|
|
|
|
|
index 1955fc4..bf48006 100644
|
|
|
|
|
|
--- a/platformtheme/kiran-theme.cpp
|
|
|
|
|
|
+++ b/platformtheme/kiran-theme.cpp
|
|
|
|
|
|
@@ -335,6 +335,7 @@ void KiranTheme::handleThemeChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
// NOTE: SchemeLoader会接收KiranAppearanceMonitor的GTK主题改变信号,重新加载配色方案
|
|
|
|
|
|
// 此处只需等到下一个事件循环,通知QGuiApplication重新更新palette
|
|
|
|
|
|
+
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
|
QTimer::singleShot(0, [this] {
|
|
|
|
|
|
// 此事件会促使QGuiApplication重新从QPlatformTheme中获取系统级别的QPalette
|
|
|
|
|
|
@@ -356,8 +357,15 @@ void KiranTheme::handleThemeChanged()
|
|
|
|
|
|
///FIXME:
|
|
|
|
|
|
///1.后续看是否有更好的方式能应用更新系统级别QPalette
|
|
|
|
|
|
///2.加入判断是否外部自定义设置Application palette,若外部自定义设置了,则应不做处理
|
|
|
|
|
|
+
|
|
|
|
|
|
+ QPalette* oldPalette = nullptr;
|
|
|
|
|
|
+ oldPalette = QGuiApplicationPrivate::app_pal;
|
|
|
|
|
|
+
|
|
|
|
|
|
QGuiApplicationPrivate::app_pal = new QPalette(*palette(SystemPalette));
|
|
|
|
|
|
|
|
|
|
|
|
+ if( oldPalette )
|
|
|
|
|
|
+ delete oldPalette;
|
|
|
|
|
|
+
|
|
|
|
|
|
// 该接口原本用于windows通知窗口主题变化时使用,现用来通知调用QGuiApplicationPrivate::notifyThemeChanged
|
|
|
|
|
|
QGuiApplicationPrivate::processThemeChanged(&event);
|
|
|
|
|
|
emit qApp->paletteChanged(*palette(SystemPalette));
|
|
|
|
|
|
--
|
|
|
|
|
|
2.33.0
|
|
|
|
|
|
|