From 4c288190000ea6c9f7148d44e8e12d882256e217 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 3 Feb 2010 15:52:28 +1000 Subject: Avoid crash on shutdown if model is destroyed before view. --- src/declarative/graphicsitems/qmlgraphicsgridview.cpp | 10 +++++++--- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 890d3ad..7105300 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -151,7 +151,7 @@ class QmlGraphicsGridViewPrivate : public QmlGraphicsFlickablePrivate public: QmlGraphicsGridViewPrivate() - : model(0), currentItem(0), flow(QmlGraphicsGridView::LeftToRight) + : currentItem(0), flow(QmlGraphicsGridView::LeftToRight) , visiblePos(0), visibleIndex(0) , currentIndex(-1) , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1) , highlightComponent(0), highlight(0), trackedItem(0) @@ -307,7 +307,7 @@ public: } } - QmlGraphicsVisualModel *model; + QGuard model; QVariant modelVariant; QList visibleItems; QHash unrequestedItems; @@ -350,6 +350,7 @@ void QmlGraphicsGridViewPrivate::init() void QmlGraphicsGridViewPrivate::clear() { + qDebug() << "clearing items" << visibleItems.count(); for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); visibleItems.clear(); @@ -384,13 +385,16 @@ FxGridItem *QmlGraphicsGridViewPrivate::createItem(int modelIndex) void QmlGraphicsGridViewPrivate::releaseItem(FxGridItem *item) { Q_Q(QmlGraphicsGridView); - if (!item) + if (!item || !model) return; if (trackedItem == item) { QObject::disconnect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); QObject::disconnect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); trackedItem = 0; } + qDebug() << "release" << item; + qDebug() << " item" << item->item; + qDebug() << " model" << model; if (model->release(item->item) == 0) { // item was not destroyed, and we no longer reference it. unrequestedItems.insert(item->item, model->indexOf(item->item, q)); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index ad0aa04..8fb7c84 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -210,7 +210,7 @@ class QmlGraphicsListViewPrivate : public QmlGraphicsFlickablePrivate, private Q public: QmlGraphicsListViewPrivate() - : model(0), currentItem(0), orient(QmlGraphicsListView::Vertical) + : currentItem(0), orient(QmlGraphicsListView::Vertical) , visiblePos(0), visibleIndex(0) , averageSize(100.0), currentIndex(-1), requestedIndex(-1) , highlightRangeStart(0), highlightRangeEnd(0) @@ -495,7 +495,7 @@ public: virtual void flickX(qreal velocity); virtual void flickY(qreal velocity); - QmlGraphicsVisualModel *model; + QGuard model; QVariant modelVariant; QList visibleItems; QHash unrequestedItems; @@ -615,7 +615,7 @@ FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) { Q_Q(QmlGraphicsListView); - if (!item) + if (!item || !model) return; if (trackedItem == item) { const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); -- cgit v0.12