-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: DPlatformTheme::property not work #219
Conversation
Synchronize source files from linuxdeepin/qt5platform-plugins. Source-pull-request: linuxdeepin/qt5platform-plugins#219
Synchronize source files from linuxdeepin/qt5platform-plugins. Source-pull-request: linuxdeepin/qt5platform-plugins#219
Synchronize source files from linuxdeepin/qt5platform-plugins. Source-pull-request: linuxdeepin/qt5platform-plugins#219
@@ -411,7 +411,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)) { | |||
&& index >= m_firstProperty + m_propertyCount)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该不会有这种低级错误才对,确定这里应该加上 m_propertyCount ?会不会导致原本应该从 m_settings 里读取的属性读不到了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问题说的就是调用属性的 read
方法 themeName
可以, 无法通过 property("themeName")
读取到正确的值。
QByteArray DPlatformTheme::themeName() const
{
// FETCH_PROPERTY("Net/ThemeName", themeName)
D_DC(DPlatformTheme);
QVariant value = d->theme->getSetting(QByteArrayLiteral("Net/ThemeName"));
if (d->fallbackProperty && !value.isValid() && d->parent)
return d->parent->themeName();
return value.toByteArray();
}
themeName() 会通过私有成员 d->theme ->getSetting
获取 xsettings
中的 Net/ThemeName
,如果直接 property("themeName")
会到 xsettings 中去读 themeName
自然是读不到的无效值。
修改方案就是 如果是原来的属性就 fallback
到源对象的 read
方法,即 m_base->qt_metacall(_c, _id, _a);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
{
Q_OBJECT
Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName NOTIFY applicationDisplayNameChanged)
Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName)
Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
Q_PROPERTY(QString platformName READ platformName STORED false)
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
Q_PROPERTY(QScreen *primaryScreen READ primaryScreen NOTIFY primaryScreenChanged STORED false)
}
const QMetaObject *metaObj = qGuiApp->metaObject();
QMetaObjectBuilder ob;
ob.addMetaObject(metaObj);
int offset = metaObj->propertyOffset();
int count = ob.propertyCount(); // metaObj->propertyCount();包含了 parent 的 property
for (int i = offset; i < count + offset; ++i) {
qInfo() << "[" << i << "]" << metaObj->property(i).name();
}
[ 6 ] windowIcon
[ 7 ] applicationDisplayName
[ 8 ] desktopFileName
[ 9 ] layoutDirection
[ 10 ] platformName
[ 11 ] quitOnLastWindowClosed
[ 12 ] primaryScreen
Synchronize source files from linuxdeepin/qt5platform-plugins. Source-pull-request: linuxdeepin/qt5platform-plugins#219
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, kegechen The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
warning: comparison of different enumeration types in switch statement ('QVariant::Type' and 'QMetaType::Type')
buildNativeSettings 之后 metaobject 被替换了 不会走原来的 read 方法了。 读写属性时如果是 base 对象原始属性 fallback 到 base 对象的 qt_metacall 方法 Issue: linuxdeepin/dtk#101
Synchronize source files from linuxdeepin/qt5platform-plugins. Source-pull-request: linuxdeepin/qt5platform-plugins#219
buildNativeSettings 之后 metaobject 被替换了
不会走原来的 read 方法了。
这里如果读取时 xsettings 中如果没有 fallback 到
base 对象的 read 方法
Issue: linuxdeepin/dtk#101