aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickcombobox.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-06-12 11:11:38 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-06-12 11:37:30 +0000
commitfe98f10bc7a3d9e396528965a4d42e89a6d8e7d2 (patch)
treebf299093884858f8bf84dc7a19b1e493a66877fa /src/quicktemplates2/qquickcombobox.cpp
parentaf96b35bf4487279357a76bd02a926c1b7f528bb (diff)
ComboBox: fix QObject list value models
When ComboBox::model is bound to a QObjectList property, the effective type of the model is QVariant(QQmlListReference) and things work as expected. When a similar QObjectList is constructed by hand in JS, or returned from an invokable method, the effective type of the model is QVariantList(QObjectStar) instead. In this scenario, we have to help QQuickComboBoxDelegateModel::stringValue() to lookup the property that matches the given textRole. Change-Id: Ib44c912cf647e1cd98c5608436427d31caf80d97 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickcombobox.cpp')
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index d987182c..00785598 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -202,6 +202,10 @@ QString QQuickComboBoxDelegateModel::stringValue(int index, const QString &role)
if (data.count() == 1 && role == QLatin1String("modelData"))
return data.first().toString();
return data.value(role).toString();
+ } else if (object.userType() == QMetaType::QObjectStar) {
+ const QObject *data = object.value<QObject *>();
+ if (data && role != QLatin1String("modelData"))
+ return data->property(role.toUtf8()).toString();
}
}
return QQmlDelegateModel::stringValue(index, role);