diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-04 09:11:50 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-04 11:22:37 +0100 |
commit | e236faa75f446aa3378fb013cce6598c9e076ccb (patch) | |
tree | 01f08e493948a122c7a1ebdd3f98b94c6b75cc19 /src/corelib/kernel/qproperty.h | |
parent | e1440dd7bc1a5da9a536f88b9733d04ec8fa6e61 (diff) |
QBindable: Disallow mutation if read-only
If a QBindable is created from a computed property, it is not possible
to actually set a value or a binding. If we try to do it anyway, we'd
get a crash. Thus we now check whether the function pointer is null
before invoking it.
Pick-to: 6.0
Task-number: QTBUG-87153
Change-Id: I5bedb9080ccf79d9b8166b80d5733d095ed76f8d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/kernel/qproperty.h')
-rw-r--r-- | src/corelib/kernel/qproperty.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index 946014dc6d..a533f424e8 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -630,7 +630,7 @@ public: QPropertyBinding<T> setBinding(const QPropertyBinding<T> &binding) { Q_ASSERT(!iface || binding.isNull() || binding.valueMetaType() == iface->metaType()); - return iface ? static_cast<QPropertyBinding<T> &&>(iface->setBinding(data, binding)) : QPropertyBinding<T>(); + return (iface && iface->setBinding) ? static_cast<QPropertyBinding<T> &&>(iface->setBinding(data, binding)) : QPropertyBinding<T>(); } #ifndef Q_CLANG_QDOC template <typename Functor> @@ -657,7 +657,7 @@ public: void setValue(const T &value) { - if (iface) + if (iface && iface->setter) iface->setter(data, &value); } }; |