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 05683ad15d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Fabian Kosmale 2023-02-09 20:44:23 +01:00 committed by Qt Cherry-pick Bot
parent a8caf1f771
commit 95cda280a8
1 changed files with 15 additions and 14 deletions

View File

@ -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 {