From 49210a266373dbbe072c3fb157dbde61053c5be0 Mon Sep 17 00:00:00 2001 From: ck Date: Wed, 8 Nov 2023 17:53:29 +0800 Subject: [PATCH] fix: stack overflow with property/setProperty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 1272c423 引入base 的 property/setProperty 会走自己的 read/write 方法,这里直接在 read/write 方法中调用 property/setProperty 会导致递归调用最终栈溢出崩溃 解决办法: 加一个 nativesettings 代理,并且通过同名 property/setProperty 函数隐藏父类的实现 --- xcb/dnotitlebarwindowhelper.cpp | 13 ++++++++++++- xcb/dnotitlebarwindowhelper.h | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/xcb/dnotitlebarwindowhelper.cpp b/xcb/dnotitlebarwindowhelper.cpp index 727aeb42..6a781c03 100644 --- a/xcb/dnotitlebarwindowhelper.cpp +++ b/xcb/dnotitlebarwindowhelper.cpp @@ -39,7 +39,8 @@ DNoTitlebarWindowHelper::DNoTitlebarWindowHelper(QWindow *window, quint32 window window->setFlags(window->flags() & ~Qt::FramelessWindowHint); mapped[window] = this; - m_nativeSettingsValid = DPlatformIntegration::buildNativeSettings(this, windowID); + m_settingsProxy = new QObject(this); + m_nativeSettingsValid = DPlatformIntegration::buildNativeSettings(m_settingsProxy, windowID); Q_ASSERT(m_nativeSettingsValid); // 本地设置无效时不可更新窗口属性,否则会导致setProperty函数被循环调用 @@ -446,6 +447,16 @@ void DNoTitlebarWindowHelper::updateAutoInputMaskByClipPathFromProperty() updateWindowShape(); } +bool DNoTitlebarWindowHelper::setProperty(const char *name, const QVariant &value) +{ + return m_settingsProxy ? m_settingsProxy->setProperty(name, value) : false; +} + +QVariant DNoTitlebarWindowHelper::property(const char *name) const +{ + return m_settingsProxy ? m_settingsProxy->property(name) : QVariant(); +} + bool DNoTitlebarWindowHelper::windowEvent(QEvent *event) { QWindow *w = this->window(); diff --git a/xcb/dnotitlebarwindowhelper.h b/xcb/dnotitlebarwindowhelper.h index 34bcb03f..4e52e768 100644 --- a/xcb/dnotitlebarwindowhelper.h +++ b/xcb/dnotitlebarwindowhelper.h @@ -87,6 +87,9 @@ private slots: Q_SLOT void updateWindowBlurPathsFromProperty(); Q_SLOT void updateAutoInputMaskByClipPathFromProperty(); +protected: + bool setProperty(const char *name, const QVariant &value); + QVariant property(const char *name) const; private: bool windowEvent(QEvent *event); bool isEnableSystemMove(quint32 winId); @@ -113,7 +116,7 @@ private slots: bool m_enableSystemMove = true; bool m_enableBlurWindow = false; bool m_autoInputMaskByClipPath = false; - DNativeSettings *m_settings; + QObject *m_settingsProxy = nullptr; static QHash mapped;