summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-11-30 04:30:35 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-11-30 04:31:48 (GMT)
commit46213b30d639505849d079b30e72ef8393e9a748 (patch)
tree4b144b2af2fd4cdd614e213342d27cec7550949c
parent1de080649c6b810ed6bc05e883795687ecde1f3d (diff)
downloadQt-46213b30d639505849d079b30e72ef8393e9a748.zip
Qt-46213b30d639505849d079b30e72ef8393e9a748.tar.gz
Qt-46213b30d639505849d079b30e72ef8393e9a748.tar.bz2
Correctly handle CppOwnership even when a QDeclarativeData doesn't exist
Task-number: QTBUG-15695
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp46
2 files changed, 47 insertions, 3 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index c646302..add1ab7 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -897,9 +897,7 @@ void QDeclarativeEngine::setObjectOwnership(QObject *object, ObjectOwnership own
if (!object)
return;
- // No need to do anything if CppOwnership and there is no QDeclarativeData as
- // the current ownership must be CppOwnership
- QDeclarativeData *ddata = QDeclarativeData::get(object, ownership == JavaScriptOwnership);
+ QDeclarativeData *ddata = QDeclarativeData::get(object, true);
if (!ddata)
return;
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 14755f32..7c0a316 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -135,6 +135,7 @@ private slots:
void scriptConnect();
void scriptDisconnect();
void ownership();
+ void cppOwnershipReturnValue();
void qlistqobjectMethods();
void strictlyEquals();
void compiled();
@@ -2100,6 +2101,51 @@ void tst_qdeclarativeecmascript::ownership()
}
}
+class CppOwnershipReturnValue : public QObject
+{
+ Q_OBJECT
+public:
+ CppOwnershipReturnValue() : value(0) {}
+
+ Q_INVOKABLE QObject *create() {
+ Q_ASSERT(value == 0);
+
+ value = new QObject;
+ QDeclarativeEngine::setObjectOwnership(value, QDeclarativeEngine::CppOwnership);
+ return value;
+ }
+
+ QPointer<QObject> value;
+};
+
+// QTBUG-15695.
+// Test setObjectOwnership(CppOwnership) works even when there is no QDeclarativeData
+void tst_qdeclarativeecmascript::cppOwnershipReturnValue()
+{
+ CppOwnershipReturnValue source;
+
+ {
+ QDeclarativeEngine engine;
+ engine.rootContext()->setContextProperty("source", &source);
+
+ QVERIFY(source.value == 0);
+
+ QDeclarativeComponent component(&engine);
+ component.setData("import QtQuick 1.0\nQtObject {\nComponent.onCompleted: { var a = source.create(); }\n}\n", QUrl());
+
+ QObject *object = component.create();
+
+ QVERIFY(object != 0);
+ QVERIFY(source.value != 0);
+
+ delete object;
+ }
+
+ QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion);
+
+ QVERIFY(source.value != 0);
+}
+
class QListQObjectMethodsObject : public QObject
{
Q_OBJECT