aboutsummaryrefslogtreecommitdiffstats
path: root/tests
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 /tests
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 'tests')
-rw-r--r--tests/auto/controls/data/tst_combobox.qml25
1 files changed, 25 insertions, 0 deletions
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)