summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetaobject.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-09-16 11:02:57 -0700
committerThiago Macieira <thiago.macieira@intel.com>2024-10-01 20:51:36 -0700
commit1f9ab3767ed625a090af45f26dffd10dcd05eef5 (patch)
treeeef6e3fe80e20f7f9b0562f6643f27b6484d1061 /src/corelib/kernel/qmetaobject.cpp
parentf42979cf6937c78c412fcfa25ec011fb66b48132 (diff)
QMetaProperty: fix type-punning of QFlags in write() from QString
Amends commit 46f407126ef3e94d59254012cdc34d6a4ad2faf2 ("MetaObject: store the QMetaType of the properties"), from 6.0 cycle, which made QMetaProperty::{read,write}() use the actual enum type in the QVariant. But it missed the case where the input QVariant contained a string with the enum's values. Note this is *not* a type-punning in all cases: if the type of the property was marked as a Q_FLAG, moc generates code to access it as int. That is fixed in the next commit. Drive-by compare QMetaTypes instead of their IDs, which avoids generating a call to register them. Pick-to: 6.8 6.5 See-also: https://lists.qt-project.org/pipermail/development/2024-September/045636.html Change-Id: I1cfce869090c96bb41b6fffdc20855cfa7cb2a18 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index e2e3c9b8083..48197c9d5c7 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -3788,8 +3788,10 @@ bool QMetaProperty::write(QObject *object, QVariant &&v) const
return false;
QMetaType t(mobj->d.metaTypes[data.index(mobj)]);
if (t != QMetaType::fromType<QVariant>() && t != v.metaType()) {
- if (isEnumType() && !t.metaObject() && v.metaType().id() == QMetaType::QString) {
+ if (isEnumType() && !t.metaObject() && v.metaType() == QMetaType::fromType<QString>()) {
// Assigning a string to a property of type Q_ENUMS (instead of Q_ENUM)
+ // means the QMetaType has no associated QMetaObject, so it can't
+ // do the conversion (see qmetatype.cpp:convertToEnum()).
bool ok;
if (isFlagType())
v = QVariant(menum.keysToValue(v.toByteArray(), &ok));
@@ -3797,7 +3799,8 @@ bool QMetaProperty::write(QObject *object, QVariant &&v) const
v = QVariant(menum.keyToValue(v.toByteArray(), &ok));
if (!ok)
return false;
- } else if (!v.isValid()) {
+ }
+ if (!v.isValid()) {
if (isResettable())
return reset(object);
v = QVariant(t, nullptr);