Thanks for the reply.
I understand from your reply that now i have to switch between the components , but as i will be assigning from one previous to the new delegate , again i will get a reference error , just to verify what you suggested i have written a small example which contains 2 models and 2 delegates and i try to assign it alternatively , but as i am doing the first assignment of model and delegate in the first mouse click i get refernce error as usual
qml: entering assigning model
qrc:/main.qml:57: ReferenceError: name is not defined
qrc:/main.qml:57: ReferenceError: name is not defined
qrc:/main.qml:57: ReferenceError: name is not defined
qrc:/main.qml:64: ReferenceError: mylistview is not defined
qml: entering assigning modeln
Also below i am posting the code i wrote , please can you suggest how to get out of these errors.
//////////////////////////////////////////////////////
import QtQuick 2.3
import QtQuick.Window 2.2
Window {
visible: true
MouseArea {
anchors.fill: parent
onClicked: {
console.log("entering assigning model")
mylistview.model=model2
mylistview.delegate=comp2
}
}
ListModel{
id:model1
ListElement{
name:"Element1"
}
ListElement{
name:"Element2"
}
ListElement{
name:"Element3"
}
}
ListModel{
id:model2
ListElement{
fame:"Element4"
}
ListElement{
fame:"Element5"
}
ListElement{
fame:"Element6"
}
}
Component
{
id:comp1
Row{
Rectangle
{
width:50
height:50
color:"red"
border.width: 2
border.color: "black"
Text {
text: name
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("entering assigning model")
mylistview.model=model2
mylistview.delegate=comp2
}
}
}
}
}
Component
{
id:comp2
Row{
Rectangle
{
width:50
height:50
color:"blue"
border.width: 2
border.color: "black"
Text {
text: fame
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("entering assigning model")
mylistview.delegate=comp1
mylistview.model=model1
}
}
}
}
}
ListView
{
id:mylistview
anchors.fill: parent
model:model1
delegate: comp1
}
}
////////////////////////////////////
//////////////////////////////////////////////////////
import QtQuick 2.3
import QtQuick.Window 2.2
Window {
visible: true
MouseArea {
anchors.fill: parent
onClicked: {
console.log("entering assigning model")
mylistview.model=model2
mylistview.delegate=comp2
}
}
ListModel{
id:model1
ListElement{
name:"Element1"
}
ListElement{
name:"Element2"
}
ListElement{
name:"Element3"
}
}
ListModel{
id:model2
ListElement{
fame:"Element4"
}
ListElement{
fame:"Element5"
}
ListElement{
fame:"Element6"
}
}
Component
{
id:comp1
Row{
Rectangle
{
width:50
height:50
color:"red"
border.width: 2
border.color: "black"
Text {
text: name
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("entering assigning model")
mylistview.model=model2
mylistview.delegate=comp2
}
}
}
}
}
Component
{
id:comp2
Row{
Rectangle
{
width:50
height:50
color:"blue"
border.width: 2
border.color: "black"
Text {
text: fame
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("entering assigning model")
mylistview.delegate=comp1
mylistview.model=model1
}
}
}
}
}
ListView
{
id:mylistview
anchors.fill: parent
model:model1
delegate: comp1
}
}
////////////////////////////////////
To copy to clipboard, switch view to plain text mode
Bookmarks