aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-02-28 16:19:10 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-02 22:29:57 +0100
commit76e0a3b4da22fab6c5fb94e12f3a94fba83fd042 (patch)
tree68effedde10f8bf5ce1f0dd7615008008c6e836b /src/qml/jsapi
parentac57f185d1a2203cd4b585df7bd7af01c3ec33ed (diff)
Make it possible to call QQmlEngine::setObjectOwnership at any time
QJSEngine::newQObject should call setObjectOwnership only if it wasn't called before, to preserve any policy set by the user earlier. Otherwise it's only safe to call after newQObject and then you'd have to call it _every_ time the QObject is wrapped, at all call sites. Instead this patch preserves any policy set. Task-number: QTBUG-37160 Change-Id: I6178fa38cd7f4b09d818b6f18762c21588562422 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r--src/qml/jsapi/qjsengine.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index a19c358231..1cf67a1c47 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -330,7 +330,11 @@ QJSValue QJSEngine::newQObject(QObject *object)
Q_D(QJSEngine);
QV4::ExecutionEngine *v4 = QV8Engine::getV4(d);
QV4::Scope scope(v4);
- QQmlEngine::setObjectOwnership(object, QQmlEngine::JavaScriptOwnership);
+ if (object) {
+ QQmlData *ddata = QQmlData::get(object, true);
+ if (!ddata || !ddata->explicitIndestructibleSet)
+ QQmlEngine::setObjectOwnership(object, QQmlEngine::JavaScriptOwnership);
+ }
QV4::ScopedValue v(scope, QV4::QObjectWrapper::wrap(v4, object));
return new QJSValuePrivate(v4, v);
}