diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-10-08 15:52:38 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-10-08 21:54:53 +0200 |
commit | 1243279ddc92bab67bc75e4ecb4ce793715ed11f (patch) | |
tree | b5a0e1c0458f243b540a63e5bbf1d1caa23f15b5 /src/qml/qml/qqmltypewrapper.cpp | |
parent | d4039298e710b6b79c018589bcc2145e22e1d5aa (diff) |
On QQmlTypeWrapper::toVariant(), consider attached objects
If the type wrapper does not denote a singleton, then it is an attached
object, or null.
Change-Id: I77b7f3424e41f2271392d7f24c7b682e854e0609
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmltypewrapper.cpp')
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 870d983c02..5c7e3aa520 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -111,11 +111,14 @@ QObject* QQmlTypeWrapper::singletonObject() const QVariant QQmlTypeWrapper::toVariant() const { - if (!isSingleton()) - return QVariant::fromValue<QObject *>(d()->object); - QQmlEnginePrivate *e = QQmlEnginePrivate::get(engine()->qmlEngine()); const QQmlType type = d()->type(); + + if (!isSingleton()) { + return QVariant::fromValue(qmlAttachedPropertiesObject( + d()->object, type.attachedPropertiesFunction(e))); + } + if (type.isQJSValueSingleton()) return QVariant::fromValue<QJSValue>(e->singletonInstance<QJSValue>(type)); |