diff options
3 files changed, 44 insertions, 3 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index a70886e..01cd652 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -621,7 +621,7 @@ QDeclarativeVisualDataModelParts::QDeclarativeVisualDataModelParts(QDeclarativeV QDeclarativeVisualDataModelPrivate::QDeclarativeVisualDataModelPrivate(QDeclarativeContext *ctxt) : m_listModelInterface(0), m_abstractItemModel(0), m_visualItemModel(0), m_delegate(0) -, m_context(ctxt), m_parts(0), m_delegateDataType(0), m_metaDataCreated(false) +, m_context(ctxt), m_modelDataPropId(-1), m_parts(0), m_delegateDataType(0), m_metaDataCreated(false) , m_metaDataCacheable(false), m_delegateValidated(false), m_completePending(false), m_listAccessor(0) { } @@ -1202,11 +1202,11 @@ void QDeclarativeVisualDataModel::_q_itemsChanged(int index, int count, qmlInfo(this) << "Changing role not present in item: " << roleName; } } - if (roles.count() == 1) { + if (d->m_roles.count() == 1) { // Handle the modelData role we add if there is just one role. int propId = data->modelDataPropertyId(); if (data->hasValue(propId)) { - int role = roles.at(0); + int role = d->m_roles.at(0); if (d->m_listModelInterface) { data->setValue(propId, d->m_listModelInterface->data(idx, QList<int>() << role).value(role)); } else if (d->m_abstractItemModel) { diff --git a/tests/auto/declarative/qdeclarativelistmodel/data/multipleroles.qml b/tests/auto/declarative/qdeclarativelistmodel/data/multipleroles.qml new file mode 100644 index 0000000..b8f2f32 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistmodel/data/multipleroles.qml @@ -0,0 +1,25 @@ +import Qt 4.7 +ListView { + width: 100 + height: 250 + delegate: Rectangle { + width: 100 + height: 50 + color: black ? "black": "white" + } + model: ListModel { + objectName: "listModel" + ListElement { + black: false + rounded: false + } + ListElement { + black: true + rounded: false + } + ListElement { + black: true + rounded: false + } + } +}
\ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index f456778..31cb545 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -98,6 +98,7 @@ private slots: void get_worker_data(); void get_nested(); void get_nested_data(); + void crash_model_with_multiple_roles(); }; int tst_qdeclarativelistmodel::roleFromName(const QDeclarativeListModel *model, const QString &roleName) { @@ -886,6 +887,21 @@ void tst_qdeclarativelistmodel::get_nested_data() get_data(); } +//QTBUG-13754 +void tst_qdeclarativelistmodel::crash_model_with_multiple_roles() +{ + QDeclarativeEngine eng; + QDeclarativeComponent component(&eng, QUrl::fromLocalFile(SRCDIR "/data/multipleroles.qml")); + QObject *rootItem = component.create(); + QVERIFY(component.errorString().isEmpty()); + QVERIFY(rootItem != 0); + QDeclarativeListModel *model = rootItem->findChild<QDeclarativeListModel*>("listModel"); + QVERIFY(model != 0); + + // used to cause a crash in QDeclarativeVisualDataModel + model->setProperty(0, "black", true); +} + QTEST_MAIN(tst_qdeclarativelistmodel) #include "tst_qdeclarativelistmodel.moc" |