diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2015-10-06 10:14:26 +0200 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2015-10-09 15:26:38 +0000 |
commit | de70798859e0363c8ca3133a4ed1a1092cfe47f5 (patch) | |
tree | 5341c001469aca13bf9e85e38b56f9ea3fbeb67c /src/corelib/kernel/qmetaobject.cpp | |
parent | 54b5287adf4f5b004fcf47840c7f2e1e561a90c1 (diff) |
QMetaProperty::write should reset the property if an empty QVariant is given
[ChangeLog][QtCore][QMetaProperty] write() now resets the property if an
empty QVariant is given, or set a default constructed object if the
property is not resettable
Change-Id: I9f9b57114e740f03ec4db6f223c1e8280a3d5209
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 6abec27684..820af298c0 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -3028,6 +3028,11 @@ QVariant QMetaProperty::read(const QObject *object) const Writes \a value as the property's value to the given \a object. Returns true if the write succeeded; otherwise returns \c false. + If \a value is not of the same type type as the property, a conversion + is attempted. An empty QVariant() is equivalent to a call to reset() + if this property is resetable, or setting a default-constructed object + otherwise. + \sa read(), reset(), isWritable() */ bool QMetaProperty::write(QObject *object, const QVariant &value) const @@ -3068,8 +3073,15 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const if (t == QMetaType::UnknownType) return false; } - if (t != QMetaType::QVariant && int(t) != value.userType() && !v.convert(t)) - return false; + if (t != QMetaType::QVariant && int(t) != value.userType()) { + if (!value.isValid()) { + if (isResettable()) + return reset(object); + v = QVariant(t, 0); + } else if (!v.convert(t)) { + return false; + } + } } // the status variable is changed by qt_metacall to indicate what it did |