diff options
Diffstat (limited to 'src/qml/jsapi/qjsengine.h')
-rw-r--r-- | src/qml/jsapi/qjsengine.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsengine.h b/src/qml/jsapi/qjsengine.h index db78e1b9a9..9af6fd6e7c 100644 --- a/src/qml/jsapi/qjsengine.h +++ b/src/qml/jsapi/qjsengine.h @@ -101,6 +101,13 @@ public: if constexpr (std::is_same_v<T, QJSManagedValue>) return toManagedValue(value); + if constexpr (std::is_same_v<T, QString>) { + if (targetType.flags() & QMetaType::PointerToQObject) { + return convertQObjectToString( + *reinterpret_cast<QObject *const *>(value.constData())); + } + } + if (sourceType == QMetaType::fromType<QJSValue>()) return fromScriptValue<T>(*reinterpret_cast<const QJSValue *>(value.constData())); @@ -148,6 +155,11 @@ public: if constexpr (std::is_same_v<To, QVariant>) return QVariant::fromValue(from); + if constexpr (std::is_same_v<To, QString> + && std::is_base_of_v<QObject, std::remove_const_t<std::remove_pointer_t<To>>>) { + return convertQObjectToString(from); + } + if constexpr (std::is_same_v<To, std::remove_const_t<std::remove_pointer_t<To>> const *>) { using nonConstTo = std::remove_const_t<std::remove_pointer_t<To>> *; if constexpr (std::is_same_v<From, nonConstTo>) @@ -220,6 +232,7 @@ private: bool convertVariant(const QVariant &value, QMetaType metaType, void *ptr); bool convertMetaType(QMetaType fromType, const void *from, QMetaType toType, void *to); + QString convertQObjectToString(QObject *object); template<typename T> friend inline T qjsvalue_cast(const QJSValue &); |