Reference Error: modal data is not defined - QML
-
Hi,
This is the code that i am using .
Window {
ComboBox {
x:6
y:6
width: 200
model:ListModel {
id: cbItems
ListElement { text: "Radio 1"; color: "Yellow"}
ListElement { text: "Radio 2"; color: "Green"}
ListElement { text: "Radio 3"; color: "Brown"}
}}
}
And i am getting the error : modal data is not defined.
-
Hi,
This is the code that i am using .
Window {
ComboBox {
x:6
y:6
width: 200
model:ListModel {
id: cbItems
ListElement { text: "Radio 1"; color: "Yellow"}
ListElement { text: "Radio 2"; color: "Green"}
ListElement { text: "Radio 3"; color: "Brown"}
}}
}
And i am getting the error : modal data is not defined.
-
@ODБOï said in Reference Error: modal data is not defined - QML:
hi IMHO the error message has nothing to do with the code you show us
Why do you say that?
The error message has everything to do with the code shown here. And the mistake can be seen without running the code. If you don't, running the code and interacting with it will confirm that this error message is output.@Jayasuriya When using a model with roles (
ListModel
is one) in a ComboBox you need to define thetextRole
property (and potentially thevalueRole
) to use the default delegate. You could also provide your own delegate.ComboBox { model: ListModel { id: cbItems ListElement { text: "Radio 1"; color: "Yellow"} ListElement { text: "Radio 2"; color: "Green"} ListElement { text: "Radio 3"; color: "Brown"} } textRole: "text" }
ComboBox { model: ListModel { id: cbItems ListElement { text: "Radio 1"; color: "Yellow"} ListElement { text: "Radio 2"; color: "Green"} ListElement { text: "Radio 3"; color: "Brown"} } delegate: ItemDelegate { contentItem: RowLayout { spacing: 8 Rectangle { color: model.color Layout.fillHeight: true Layout.preferredWidth: height } Label { Layout.fillHeight: true Layout.fillWidth: true text: model.text } } } }