diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-04-28 17:11:36 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-05-31 12:05:21 +0200 |
commit | 39cdf431f034121353e51768b4d1fec8b0dd35dc (patch) | |
tree | 1d8905b4801f2c9b30f215fc109aaa12caded330 /src/corelib/kernel/qobject.h | |
parent | b8b34544d0b52b6406567315a2cd4e35ec629c4a (diff) |
QObject: add setProperty() overload taking rvalue QVariant
Instead of duplicating the long-ish implementation, simply pass the
variant as pointers to const and mutable, and implement a runtime
version of std::forward.
[ChangeLog][QtCore][QObject] Added setProperty() overload taking an
rvalue QVariant.
Fixes: QTBUG-113281
Task-number: QTBUG-112762
Change-Id: Ifdc8f626ad5db138073474c3bd95ec7308c4396b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/kernel/qobject.h')
-rw-r--r-- | src/corelib/kernel/qobject.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 852f5c7053..3c102a0a85 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -292,7 +292,9 @@ public: void dumpObjectTree() const; void dumpObjectInfo() const; + QT_CORE_INLINE_SINCE(6, 6) bool setProperty(const char *name, const QVariant &value); + inline bool setProperty(const char *name, QVariant &&value); QVariant property(const char *name) const; QList<QByteArray> dynamicPropertyNames() const; QBindingStorage *bindingStorage() { return &d_ptr->bindingStorage; } @@ -345,6 +347,8 @@ protected: private: void doSetObjectName(const QString &name); + bool doSetProperty(const char *name, const QVariant *lvalue, QVariant *rvalue); + Q_DISABLE_COPY(QObject) Q_PRIVATE_SLOT(d_func(), void _q_reregisterTimers(void *)) @@ -363,6 +367,17 @@ inline QMetaObject::Connection QObject::connect(const QObject *asender, const ch const char *amember, Qt::ConnectionType atype) const { return connect(asender, asignal, this, amember, atype); } +#if QT_CORE_INLINE_IMPL_SINCE(6, 6) +bool QObject::setProperty(const char *name, const QVariant &value) +{ + return doSetProperty(name, &value, nullptr); +} +#endif // inline since 6.6 +bool QObject::setProperty(const char *name, QVariant &&value) +{ + return doSetProperty(name, &value, &value); +} + template <class T> inline T qobject_cast(QObject *object) { |