From 5207e48e469e279fe20304914e92edd73c5c641f Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 14 Jan 2011 10:51:53 +1000 Subject: Clarify Component.createObject(null) behavior. Setting the parent of the returned item does not affect its object ownership so care must be taken to ensure it is not garbage collected. Task-number: QTBUG-16630 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativecomponent.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index e2cbdcf..f716f85 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -627,6 +627,10 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q must provide a valid \a parent value or set the returned object's \l{Item::parent}{parent} property, or else the object will not be visible. + If a \a parent is not provided to createObject(), a reference to the returned object must be held so that + it is not destroyed by the garbage collector. This is regardless of Item.parent being set afterwards, + since setting the Item parent does not change object ownership; only the graphical parent is changed. + Dynamically created instances can be deleted with the \c destroy() method. See \l {Dynamic Object Management in QML} for more information. */ -- cgit v0.12 From 4f9c026a02c2ecf0d19e7aee4ecae82e64cbaee8 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 14 Jan 2011 10:57:21 +1000 Subject: Fix memory leak Task-number: QTBUG-16526 --- src/declarative/qml/qdeclarativevme.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 6d49625..fb07bef 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -938,8 +938,13 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, if (bindValues.count) ep->bindValues << bindValues; + else if (bindValues.values) + bindValues.clear(); + if (parserStatus.count) ep->parserStatus << parserStatus; + else if (parserStatus.values) + parserStatus.clear(); Q_ASSERT(stack.count() == 1); return stack.top(); -- cgit v0.12 From 22a00ee975545704cd0d70314f45f3b3ecf7ab01 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 14 Jan 2011 16:14:17 +1000 Subject: Autotest for QVariant value types --- .../qdeclarativevaluetypes/data/variant_read.qml | 9 +++++++++ tests/auto/declarative/qdeclarativevaluetypes/testtypes.h | 3 +++ .../qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/variant_read.qml diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/variant_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/variant_read.qml new file mode 100644 index 0000000..a08f3db --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/variant_read.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +MyTypeObject { + property real s_width: variant.width + property real s_height: variant.height + property variant copy: variant +} + + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h index 86cbaa5..104d22f 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h +++ b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h @@ -76,6 +76,7 @@ class MyTypeObject : public QObject Q_PROPERTY(QQuaternion quaternion READ quaternion WRITE setQuaternion NOTIFY changed) Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY changed) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) + Q_PROPERTY(QVariant variant READ variant NOTIFY changed) public: MyTypeObject() : @@ -152,6 +153,8 @@ public: QFont font() const { return m_font; } void setFont(const QFont &v) { m_font = v; emit changed(); } + QVariant variant() const { return sizef(); } + void emitRunScript() { emit runScript(); } signals: diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index a5cf051..ce857a0 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -77,6 +77,7 @@ private slots: void quaternion(); void matrix4x4(); void font(); + void variant(); void bindingAssignment(); void bindingRead(); @@ -210,6 +211,19 @@ void tst_qdeclarativevaluetypes::sizef() } } +void tst_qdeclarativevaluetypes::variant() +{ + QDeclarativeComponent component(&engine, TEST_FILE("variant_read.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(float(object->property("s_width").toDouble()), float(0.1)); + QCOMPARE(float(object->property("s_height").toDouble()), float(100923.2)); + QCOMPARE(object->property("copy"), QVariant(QSizeF(0.1, 100923.2))); + + delete object; +} + void tst_qdeclarativevaluetypes::sizereadonly() { { -- cgit v0.12