From 19a387638450a5e7d73efb665c6b6665ca5c2dd6 Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 6 Nov 2023 17:19:25 +0800 Subject: [PATCH] fix: DPlatformTheme::property not work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit buildNativeSettings 之后 metaobject 被替换了 不会走原来的 read 方法了。 读写属性时如果不是 base 对象初始化时属性 fallback 到 base 对象的 qt_metacall 方法 Issue: https://github.com/linuxdeepin/dtk/issues/101 --- src/dnativesettings.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/dnativesettings.cpp b/src/dnativesettings.cpp index f5b0bc20..503e9a15 100644 --- a/src/dnativesettings.cpp +++ b/src/dnativesettings.cpp @@ -147,12 +147,12 @@ void DNativeSettings::init(const QMetaObject *metaObject) QMetaPropertyBuilder op; switch (mp.type()) { - case QMetaType::QByteArray: - case QMetaType::QString: - case QMetaType::QColor: - case QMetaType::Int: - case QMetaType::Double: - case QMetaType::Bool: + case QVariant::ByteArray: + case QVariant::String: + case QVariant::Color: + case QVariant::Int: + case QVariant::Double: + case QVariant::Bool: op = ob.addProperty(mp); break; default: @@ -409,9 +409,12 @@ int DNativeSettings::metaCall(QMetaObject::Call _c, int _id, void ** _a) if (AllCall & (1 << _c)) { const QMetaProperty &p = property(_id); const int index = p.propertyIndex(); - // 对于本地属性,此处应该从m_settings中读写 - if (Q_LIKELY(index != m_flagPropertyIndex && index != m_allKeysPropertyIndex - && index >= m_firstProperty)) { + if (Q_LIKELY(index != m_flagPropertyIndex && + index != m_allKeysPropertyIndex && + // fix dtk#101 + // base 原有的属性(m_firstProperty ~ m_propertyCount)回退到 base 对象的 qt_metacall + // 其他属性从 m_settings 中读写 + index >= m_propertyCount)) { switch (_c) { case QMetaObject::ReadProperty: *reinterpret_cast(_a[1]) = m_settings->setting(p.name());