From 9e604dcd07d5b943520ab2a3d472bd23fdd577ec Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Thu, 17 Jan 2013 18:46:45 +0900 Subject: Fix crash in PathView Change-Id: I259e7af1755ff9615782bbce03fc41ea1957cab3 Task-number: QTBUG-29176 Reviewed-by: Alan Alpert --- src/quick/items/qquickpathview.cpp | 10 +++++++--- tests/auto/quick/qquickpathview/data/emptypath.qml | 6 ++++++ tests/auto/quick/qquickpathview/tst_qquickpathview.cpp | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/auto/quick/qquickpathview/data/emptypath.qml diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index a58ed599be..a7be50bc11 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -193,7 +193,7 @@ void QQuickPathView::initItem(int index, QQuickItem *item) if (att) { att->m_view = this; qreal percent = d->positionOfIndex(index); - if (percent < 1.0) { + if (percent < 1.0 && d->path) { foreach (const QString &attr, d->path->attributes()) att->setValue(attr.toUtf8(), d->path->attributeAt(attr, percent)); item->setZ(d->requestedZ); @@ -227,8 +227,10 @@ QQmlOpenMetaObjectType *QQuickPathViewPrivate::attachedType() if (!attType) { // pre-create one metatype to share with all attached objects attType = new QQmlOpenMetaObjectType(&QQuickPathViewAttached::staticMetaObject, qmlEngine(q)); - foreach (const QString &attr, path->attributes()) - attType->createProperty(attr.toUtf8()); + if (path) { + foreach (const QString &attr, path->attributes()) + attType->createProperty(attr.toUtf8()); + } } return attType; @@ -423,6 +425,8 @@ void QQuickPathView::pathUpdated() void QQuickPathViewPrivate::updateItem(QQuickItem *item, qreal percent) { + if (!path) + return; if (QQuickPathViewAttached *att = attached(item)) { if (qFuzzyCompare(att->m_percent, percent)) return; diff --git a/tests/auto/quick/qquickpathview/data/emptypath.qml b/tests/auto/quick/qquickpathview/data/emptypath.qml new file mode 100644 index 0000000000..d68cf4491b --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/emptypath.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +PathView { + model: 1 + delegate: Item {} +} diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index a7e0f2feb4..8821203902 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -118,6 +118,7 @@ private slots: void pathUpdateOnStartChanged(); void package(); void emptyModel(); + void emptyPath(); void closed(); void pathUpdate(); void visualDataModel(); @@ -1373,6 +1374,19 @@ void tst_QQuickPathView::emptyModel() delete window; } +void tst_QQuickPathView::emptyPath() +{ + QQuickView *window = createView(); + + window->setSource(testFileUrl("emptypath.qml")); + qApp->processEvents(); + + QQuickPathView *pathview = qobject_cast(window->rootObject()); + QVERIFY(pathview != 0); + + delete window; +} + void tst_QQuickPathView::closed() { QQmlEngine engine; -- cgit v1.2.3