diff --git a/src/dnativesettings.cpp b/src/dnativesettings.cpp index 050cba17..ba43c316 100644 --- a/src/dnativesettings.cpp +++ b/src/dnativesettings.cpp @@ -27,9 +27,18 @@ #define VALID_PROPERTIES "validProperties" #define ALL_KEYS "allKeys" +#define PROXY_OBJ "_d_proxyObject" DPP_BEGIN_NAMESPACE +static inline QObject *proxyObject(QObject *obj) +{ + if (qintptr ptr = qvariant_cast(obj->property(PROXY_OBJ))) + return reinterpret_cast(ptr); + + return obj; +} + QHash DNativeSettings::mapped; /* * 通过覆盖QObject的qt_metacall虚函数,检测base object中自定义的属性列表,将xwindow对应的设置和object对象中的属性绑定到一起使用 @@ -192,7 +201,7 @@ void DNativeSettings::init(const QMetaObject *metaObject) } // 将属性状态设置给对象 - m_base->setProperty(VALID_PROPERTIES, validProperties); + proxyObject(m_base)->setProperty(VALID_PROPERTIES, validProperties); // 将所有属性名称设置给对象 if (allKeyPropertyTyep == qMetaTypeId>()) { @@ -360,12 +369,12 @@ void DNativeSettings::onPropertyChanged(const QByteArray &name, const QVariant & { bool ok = false; - qint64 flags = handle->m_base->property(VALID_PROPERTIES).toLongLong(&ok); + qint64 flags = proxyObject(handle->m_base)->property(VALID_PROPERTIES).toLongLong(&ok); // 更新有效属性的标志位 if (ok) { qint64 flag = (1 << property_index); flags = property.isValid() ? flags | flag : flags & ~flag; - handle->m_base->setProperty(VALID_PROPERTIES, flags); + proxyObject(handle->m_base)->setProperty(VALID_PROPERTIES, flags); } } @@ -373,7 +382,7 @@ void DNativeSettings::onPropertyChanged(const QByteArray &name, const QVariant & if (p.hasNotifySignal()) { // 通知属性改变 - p.notifySignal().invoke(handle->m_base); + p.notifySignal().invoke(proxyObject(handle->m_base)); } } @@ -415,7 +424,7 @@ int DNativeSettings::metaCall(QMetaObject::Call _c, int _id, void ** _a) const int index = p.propertyIndex(); // 对于本地属性,此处应该从m_settings中读写 if (Q_LIKELY(index != m_flagPropertyIndex && index != m_allKeysPropertyIndex - && index >= m_firstProperty + m_propertyCount)) { + && index >= m_firstProperty)) { switch (_c) { case QMetaObject::ReadProperty: *reinterpret_cast(_a[1]) = m_settings->setting(p.name());