From b62f70fe9fd36252e9ae31e910323a130f458ddd Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 3 Jan 2023 12:20:33 +0100 Subject: [PATCH] QJSEngine: Document new conversion functions ... and drop the notes about QMetaType. You can get a metatype for any type these days. Pick-to: 6.5 Change-Id: Iaae53830dfb9cbe81975c3f73cf6cbe33494884a Reviewed-by: Fabian Kosmale --- src/qml/jsapi/qjsengine.cpp | 44 ++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index d9a2abd3a9..54efde52d7 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -956,24 +956,57 @@ QString QJSEngine::convertQObjectToString(QObject *object) /*! \fn template QJSValue QJSEngine::toScriptValue(const T &value) Creates a QJSValue with the given \a value. - This works with any type \c{T} that has a \c{QMetaType}. \sa fromScriptValue(), coerceValue() */ +/*! \fn template QJSManagedValue QJSEngine::toManagedValue(const T &value) + + Creates a QJSManagedValue with the given \a value. + + \sa fromManagedValue(), coerceValue() +*/ + +/*! \fn template QJSPrimitiveValue QJSEngine::toPrimitiveValue(const T &value) + + Creates a QJSPrimitiveValue with the given \a value. + + Since QJSPrimitiveValue can only hold int, bool, double, QString, and the + equivalents of JavaScript \c null and \c undefined, the value will be + coerced aggressively if you pass any other type. + + \sa fromPrimitiveValue(), coerceValue() +*/ + /*! \fn template T QJSEngine::fromScriptValue(const QJSValue &value) Returns the given \a value converted to the template type \c{T}. - This works with any type \c{T} that has a \c{QMetaType}. \sa toScriptValue(), coerceValue() */ +/*! \fn template T QJSEngine::fromManagedValue(const QJSManagedValue &value) + + Returns the given \a value converted to the template type \c{T}. + + \sa toManagedValue(), coerceValue() +*/ + +/*! \fn template T QJSEngine::fromPrimitiveValue(const QJSPrimitiveValue &value) + + Returns the given \a value converted to the template type \c{T}. + + Since QJSPrimitiveValue can only hold int, bool, double, QString, and the + equivalents of JavaScript \c null and \c undefined, the value will be + coerced aggressively if you request any other type. + + \sa toPrimitiveValue(), coerceValue() +*/ + /*! \fn template T QJSEngine::fromVariant(const QVariant &value) Returns the given \a value converted to the template type \c{T}. - This works with any type \c{T} that has a \c{QMetaType}. The - conversion is done in JavaScript semantics. Those differ from + The conversion is done in JavaScript semantics. Those differ from qvariant_cast's semantics. There are a number of implicit conversions between JavaScript-equivalent types that are not performed by qvariant_cast by default. @@ -984,8 +1017,7 @@ QString QJSEngine::convertQObjectToString(QObject *object) /*! \fn template T QJSEngine::coerceValue(const From &from) Returns the given \a from converted to the template type \c{To}. - This works with any type \c{T} that has a \c{QMetaType}. The - conversion is done in JavaScript semantics. Those differ from + The conversion is done in JavaScript semantics. Those differ from qvariant_cast's semantics. There are a number of implicit conversions between JavaScript-equivalent types that are not performed by qvariant_cast by default. This method is a generalization of