aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine/tst_qjsengine.cpp
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 /tests/auto/qml/qjsengine/tst_qjsengine.cpp
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 'tests/auto/qml/qjsengine/tst_qjsengine.cpp')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index f5046395dd..a11185431b 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -565,6 +565,19 @@ void tst_QJSEngine::newQObject_ownership()
QVERIFY(child != 0);
delete parent;
}
+ {
+ QPointer<QObject> ptr = new QObject();
+ QVERIFY(ptr != 0);
+ {
+ QQmlEngine::setObjectOwnership(ptr.data(), QQmlEngine::CppOwnership);
+ QJSValue v = eng.newQObject(ptr);
+ }
+ eng.collectGarbage();
+ if (ptr)
+ QGuiApplication::sendPostedEvents(ptr, QEvent::DeferredDelete);
+ QVERIFY(!ptr.isNull());
+ delete ptr.data();
+ }
}
void tst_QJSEngine::newQObject_deletedEngine()