From 189d2660968368532761586ffd495eb6c18cdbdf Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 29 Jun 2010 10:43:42 +1000 Subject: Ensure Loader item change listener is removed when Loader is destroyed Task-number: QTBUG-11771 --- src/declarative/graphicsitems/qdeclarativeloader.cpp | 10 +++++++++- .../declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp | 9 ++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 25b1119..c8c9e44 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -174,7 +174,7 @@ void QDeclarativeLoaderPrivate::initResize() QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent) : QDeclarativeItem(*(new QDeclarativeLoaderPrivate), parent) { - Q_D(QDeclarativeItem); + Q_D(QDeclarativeLoader); d->flags |= QGraphicsItem::ItemIsFocusScope; } @@ -183,6 +183,14 @@ QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent) */ QDeclarativeLoader::~QDeclarativeLoader() { + Q_D(QDeclarativeLoader); + if (d->item) { + if (QDeclarativeItem *qmlItem = qobject_cast(d->item)) { + QDeclarativeItemPrivate *p = + static_cast(QGraphicsItemPrivate::get(qmlItem)); + p->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry); + } + } } /*! diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp index d047a2a..b0b7a3b 100644 --- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp +++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp @@ -47,6 +47,7 @@ #include #include #include "testhttpserver.h" +#include "../../../shared/util.h" #define SERVER_PORT 14450 @@ -176,9 +177,7 @@ void tst_QDeclarativeLoader::clear() QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast(loader)->children().count(), 1); - QTest::qWait(500); - - QVERIFY(loader->item() == 0); + QTRY_VERIFY(loader->item() == 0); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QDeclarativeLoader::Null); QCOMPARE(static_cast(loader)->children().count(), 0); @@ -239,8 +238,8 @@ void tst_QDeclarativeLoader::urlToComponent() "}" ) , TEST_FILE("")); QDeclarativeLoader *loader = qobject_cast(component.create()); - QTest::qWait(500); - QVERIFY(loader != 0); + QTest::qWait(200); + QTRY_VERIFY(loader != 0); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast(loader)->children().count(), 1); -- cgit v0.12