diff options
-rw-r--r-- | src/quicktemplates2/qquickcombobox.cpp | 4 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 25 |
2 files changed, 29 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); diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 07e49e70..f231ebf8 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -156,6 +156,31 @@ TestCase { compare(control.currentText, "") } + function test_qobjects() { + var control = createTemporaryObject(emptyBox, testCase, {textRole: "text"}) + verify(control) + + var obj1 = Qt.createQmlObject("import QtQml 2.0; QtObject { property string text: 'one' }", control) + var obj2 = Qt.createQmlObject("import QtQml 2.0; QtObject { property string text: 'two' }", control) + var obj3 = Qt.createQmlObject("import QtQml 2.0; QtObject { property string text: 'three' }", control) + + control.model = [obj1, obj2, obj3] + + compare(control.count, 3) + compare(control.currentIndex, 0) + compare(control.currentText, "one") + + control.currentIndex = 2 + compare(control.currentIndex, 2) + compare(control.currentText, "three") + + control.model = null + compare(control.model, null) + compare(control.count, 0) + compare(control.currentIndex, -1) + compare(control.currentText, "") + } + function test_number() { var control = createTemporaryObject(comboBox, testCase) verify(control) |