diff options
Diffstat (limited to 'src/qml/jsapi/qjsengine.cpp')
-rw-r--r-- | src/qml/jsapi/qjsengine.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index c6caae2f09..831287d0b3 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -565,6 +565,24 @@ QQmlPropertyCache *QJSEnginePrivate::createCache(const QMetaObject *mo) } } +/*! + \since 5.5 + \relates QJSEngine + + Returns the QJSEngine associated with \a object, if any. + + This function is useful if you have exposed a QObject to the JavaScript environment + and later in your program would like to regain access. It does not require you to + keep the wrapper around that was returned from QJSEngine::newQObject(). + */ +QJSEngine *qjsEngine(const QObject *object) +{ + QQmlData *data = QQmlData::get(object, false); + if (!data || data->jsWrapper.isNullOrUndefined()) + return 0; + return data->jsWrapper.engine()->jsEngine(); +} + QT_END_NAMESPACE #include "moc_qjsengine.cpp" |