aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2/doc/snippets/qtquickcontrols2-combobox-find.qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2021-06-08 15:58:18 +0200
committerMitch Curtis <mitch.curtis@qt.io>2021-06-10 14:33:09 +0200
commit332011c8e6a96cd2b0c685b72f96337660f690e0 (patch)
tree9952ca1f799b65c7fd91d0a65ab043b92361fbbe /src/quickcontrols2/doc/snippets/qtquickcontrols2-combobox-find.qml
parentde66c7e6c4ae03d1da2225dc443a028bf5f6e722 (diff)
Doc: some ComboBox functions must be used after component completion
The internal QQmlDelegate model may not be ready until after componentComplete() is called. For example, the following code will print -1 for the find call, even though printing the model will show the "Hello" entry: ComboBox { id: comboBug anchors.centerIn: parent model: ["123", "BlaBla", "Hello", "Turtle"] currentIndex: { console.log("Model: " + comboBug.model) console.log("Find: " + comboBug.find("Hello")) return comboBug.find("Hello") } } Fixes: QTBUG-94257 Pick-to: 6.1 6.2 Change-Id: I6e8c2a4eb8ca7ffca0a38d2f2e914cf791d3bd2e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/quickcontrols2/doc/snippets/qtquickcontrols2-combobox-find.qml')
-rw-r--r--src/quickcontrols2/doc/snippets/qtquickcontrols2-combobox-find.qml40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/quickcontrols2/doc/snippets/qtquickcontrols2-combobox-find.qml b/src/quickcontrols2/doc/snippets/qtquickcontrols2-combobox-find.qml
new file mode 100644
index 00000000..c14ebbbe
--- /dev/null
+++ b/src/quickcontrols2/doc/snippets/qtquickcontrols2-combobox-find.qml
@@ -0,0 +1,40 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick
+import QtQuick.Controls
+
+//! [find]
+ComboBox {
+ model: ListModel {
+ ListElement { text: "Banana" }
+ ListElement { text: "Apple" }
+ ListElement { text: "Coconut" }
+ }
+ Component.onCompleted: currentIndex = find("Coconut")
+}
+//! [find]