stereoMatching
6th July 2013, 06:22
import QtQuick 2.1
import QtQuick.Controls 1.0
Rectangle {
id: root
width: 500
height: 500
state: "one"
ListModel{
id: one
}
ListModel{
id: two
}
function changeModel(){
if(state == "one"){
one.append({"source": "aaa"})
return one
}else{
two.append({"source": "bbb"})
return two
}
}
Row{
Button{
id: buttonOne
text: "One"
onClicked: {
root.state = "one"
}
}
Button{
id: buttonTwo
text: "Two"
onClicked: {
root.state = "two"
}
}
TableView{
id: tableView
model: changeModel()
TableViewColumn {
title: "image"
delegate: Text{ text: tableView.model.get(styleData.row).source }
}
}
}
}
When I click the “Two†button, there are always an error message
qrc:/main.qml:59: TypeError: Cannot read property ‘source’ of undefined
How could I change the model dynamically?What kind of mistake I make?Thanks
import QtQuick.Controls 1.0
Rectangle {
id: root
width: 500
height: 500
state: "one"
ListModel{
id: one
}
ListModel{
id: two
}
function changeModel(){
if(state == "one"){
one.append({"source": "aaa"})
return one
}else{
two.append({"source": "bbb"})
return two
}
}
Row{
Button{
id: buttonOne
text: "One"
onClicked: {
root.state = "one"
}
}
Button{
id: buttonTwo
text: "Two"
onClicked: {
root.state = "two"
}
}
TableView{
id: tableView
model: changeModel()
TableViewColumn {
title: "image"
delegate: Text{ text: tableView.model.get(styleData.row).source }
}
}
}
}
When I click the “Two†button, there are always an error message
qrc:/main.qml:59: TypeError: Cannot read property ‘source’ of undefined
How could I change the model dynamically?What kind of mistake I make?Thanks