0

I have one listView, on mouseArea after clicking on listview elements should append in Rectangle.but first elements appends but later saying that noting to push

QML debugging is enabled. Only use this in a safe environment.
qml: Layout
qml: Layout_send_id
qrc:/main.qml:62:9: QML StackView: push: nothing to push

Images for references

first click

second click

I want continue appending but it is replacing and show error as nothing to push

import QtQuick.Controls.Styles 1.4
import QtQuick.Controls.Material 2.4
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.4
import QtQuick 2.4
import QtQuick.Controls 2.12

ApplicationWindow {

    id:mainWindow
    visible: true
    width: 640
    height: 480
    title: qsTr("Scroll vertical horizontal")

    Rectangle{

        id:selectedItem
        x:parent.width*0.2
        y:parent.height*0.05
        border.color: "black"
        width: parent.width*0.3
        height: parent.height*0.25

        StackView{
            id:layoutStack
        }
    }
    
    StackLayout{
        id:stackModel
    }


    Item{
        id:element
        Rectangle{

        width: val*10
        height: 20
        border.color: "green"

            Text {
                id: input
            }
        }
    }

    ListModel{
        id:listModel
        ListElement{
            name : "Layout"
        }
        ListElement{
            name : "Layout_send_id"
        }
        ListElement{
            name : "Layout_received_id"
        }
    }

    property var val

    ListView{
        id:listView
        x:parent.width*0.2
        y:parent.height*0.35
        model: listModel
        width: 200
        height: 250

        delegate: Rectangle{
            id:recta
            width: parent.width
            height: 20
            border.color: "brown"
            Text {
                id: name
                text: model.name
            }

            MouseArea{
                id:clickArea
                anchors.fill: parent
                onClicked: {
                    val = (model.name).length
                    console.log(model.name)
                    input.text =model.name
                    layoutStack.push(element)
                }
            }
        }

    }
}
JarMan
  • 7,589
  • 1
  • 10
  • 25
  • Because you are only pushing the same element, and the element also isn't replaced, but you are only updating its text, and you think it has been replaced. check this link: [Dynamic QML Object Creation](https://doc.qt.io/qt-6/qtqml-javascript-dynamicobjectcreation.html) – SMR Feb 21 '23 at 13:33
  • @SMR If you see in reference Images I'm updating rectangle size and text both ,so still it will not considered as new element? – Rajendra Aware Feb 22 '23 at 15:16
  • No, updating all the properties of an object **does not make a new one**, and pushing an object **does not create a copy of it**, thus you should construct a new object dynamically and push it to `StackView`. – SMR Feb 23 '23 at 04:53
  • @SMR I have added some line of code in MouseArea and not coming that error. var compo = Qt.createComponent("Tag.qml") if(compo.status === Component.Ready){ var object = compo.createObject(layoutStack) layoutStack.push(object) } – Rajendra Aware Feb 23 '23 at 07:00

0 Answers0