diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-02-09 20:44:23 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-13 19:51:23 +0000 |
commit | 301c09c7ad39a24ce1d3e9544c1cff78707e740a (patch) | |
tree | 2a8fecb270a764ab19ab371b3070e2f7e3639587 | |
parent | 73bcf488f1c10969490777f6a9856dbf37371dc8 (diff) |
Fix locale example
Instead of fetching data from the view, we should rather fetch it from
the model, which avoids a bug with casting when the currentItem is null.
Use the opportunity to use a typed list for the model instead of a plain
JS array.
Original-patch-by: Kai Köhne <kai.koehne@qt.io>
Change-Id: Ib23fb31b3d0a2c309c98bf762cea1a8c05080c38
Reviewed-by: Kai Köhne <kai.koehne@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 05683ad15d068b42b8b54d75a3c5377e994bface)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/qml/locale/locale.qml | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/examples/qml/locale/locale.qml b/examples/qml/locale/locale.qml index 4308dd0c82..35875a3177 100644 --- a/examples/qml/locale/locale.qml +++ b/examples/qml/locale/locale.qml @@ -8,6 +8,19 @@ Rectangle { width: 320 height: 480 color: "lightgray" + property list<string> locales: ([ + "en_US", + "en_GB", + "fi_FI", + "de_DE", + "ar_SA", + "hi_IN", + "zh_CN", + "th_TH", + "fr_FR", + "nb_NO", + "sv_SE" + ]) component LocaleDelegate: Text { required property var modelData @@ -23,7 +36,7 @@ Rectangle { } } - property string locale: (view.currentItem as LocaleDelegate).locale + property string locale: view.currentIndex === -1 ? "en_US" : root.locales[view.currentIndex] Text { id: title @@ -43,19 +56,7 @@ Rectangle { clip: true focus: true anchors.fill: parent - model: [ - "en_US", - "en_GB", - "fi_FI", - "de_DE", - "ar_SA", - "hi_IN", - "zh_CN", - "th_TH", - "fr_FR", - "nb_NO", - "sv_SE" - ] + model: root.locales delegate: LocaleDelegate {} highlight: Rectangle { |