aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r--src/qml/jsapi/qjsengine.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/qml/jsapi/qjsengine.h b/src/qml/jsapi/qjsengine.h
index c04e47d34e..dbeecb45ae 100644
--- a/src/qml/jsapi/qjsengine.h
+++ b/src/qml/jsapi/qjsengine.h
@@ -139,12 +139,21 @@ public:
return toPrimitiveValue(value);
if constexpr (std::is_same_v<T, QString>) {
- if (targetType.flags() & QMetaType::PointerToQObject) {
+ if (sourceType.flags() & QMetaType::PointerToQObject) {
return convertQObjectToString(
*reinterpret_cast<QObject *const *>(value.constData()));
}
}
+ if constexpr (std::is_same_v<QObject, std::remove_const_t<std::remove_pointer_t<T>>>) {
+ if (sourceType.flags() & QMetaType::PointerToQObject) {
+ return *static_cast<QObject *const *>(value.constData());
+
+ // We should not access source->metaObject() here since that may trigger some
+ // rather involved code. convertVariant() can do this using property caches.
+ }
+ }
+
if (sourceType == QMetaType::fromType<QJSValue>())
return fromScriptValue<T>(*reinterpret_cast<const QJSValue *>(value.constData()));
@@ -175,7 +184,7 @@ public:
template<typename From, typename To>
inline To coerceValue(const From &from)
{
- if constexpr (std::is_same_v<From, To>)
+ if constexpr (std::is_base_of_v<To, From>)
return from;
if constexpr (std::is_same_v<To, QJSValue>)