From 0925c51c5988bee7ee96944de2d857b2132ebe65 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 15 Nov 2022 11:57:47 +0100 Subject: QJSEngine: Optimize conversion from QObject* to QString This is commonly done for logging. With this in place we can have the code generator use coerceType() for such constructs. [ChangeLog][QML][Important Behavior Changes] You can implement custom toString() methods for your QML objects in JavaScript or in C++. Those methods don't actually have to return a string. Previously, whatever return value the method generated was forwarded as-is. Now it is coerced to a string. Change-Id: I4a9721a6948be0c24a36b31d453a74bd747db729 Reviewed-by: Fabian Kosmale Reviewed-by: Sami Shalayel --- src/qml/jsapi/qjsengine.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/qml/jsapi/qjsengine.cpp') diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index c15b5c1ccd..8b0b650c1f 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -920,6 +920,12 @@ bool QJSEngine::convertMetaType(QMetaType fromType, const void *from, QMetaType return QV4::ExecutionEngine::metaTypeFromJS(handle()->fromData(fromType, from), toType, to); } +QString QJSEngine::convertQObjectToString(QObject *object) +{ + return QV4::QObjectWrapper::objectToString( + handle(), object ? object->metaObject() : nullptr, object); +} + /*! \fn template QJSValue QJSEngine::toScriptValue(const T &value) Creates a QJSValue with the given \a value. -- cgit v1.2.3