From e0167ee787bd0d28a9de0278c3f70f30151e2be6 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 10 Aug 2010 11:50:49 +1000 Subject: Don't double-add item change listeners. When a Repeater was used as the child of an Item binding to childrenRect, the item change listener was being added twice for the items created by the Repeater. Task-number: QTBUG-12722 (cherry picked from commit 6feb5b75ce96aeeefee189af003949db8c031519) --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 4 ++-- .../qdeclarativeitem/data/childrenRectBug3.qml | 15 +++++++++++++++ .../declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 06862f1..ccbdce8 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2740,12 +2740,12 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change, } break; case ItemChildAddedChange: - if (d->_contents) + if (d->_contents && d->componentComplete) d->_contents->childAdded(qobject_cast( value.value())); break; case ItemChildRemovedChange: - if (d->_contents) + if (d->_contents && d->componentComplete) d->_contents->childRemoved(qobject_cast( value.value())); break; diff --git a/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml new file mode 100644 index 0000000..f19ab4f --- /dev/null +++ b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml @@ -0,0 +1,15 @@ +import Qt 4.7 + +Rectangle { + width: 300 + height: 300 + + Rectangle { + height: childrenRect.height + + Repeater { + model: 1 + Rectangle { } + } + } +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index d76d360..25ca157 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -75,6 +75,7 @@ private slots: void childrenRect(); void childrenRectBug(); void childrenRectBug2(); + void childrenRectBug3(); void childrenProperty(); void resourcesProperty(); @@ -780,6 +781,17 @@ void tst_QDeclarativeItem::childrenRectBug2() delete canvas; } +// QTBUG-12722 +void tst_QDeclarativeItem::childrenRectBug3() +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/childrenRectBug3.qml")); + canvas->show(); + + //don't crash on delete + delete canvas; +} + template T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { -- cgit v0.12