UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    ListView - append is not a function

    Scheduled Pinned Locked Moved Solved App Development
    3 Posts 2 Posters 313 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • 0 Offline
        007fred50
        last edited by

        Hello All,

        I trying to make ListView and delete that item.
        My Question is why can't i add an item to ListView?

        Here is my Code

        import QtQuick 2.7
        import Ubuntu.Components 1.3
        //import QtQuick.Controls 2.2
        import QtQuick.Layouts 1.3
        import Qt.labs.settings 1.0
        import QtQuick.Controls 2.5
        
        MainView {
            id: root
            objectName: 'mainView'
            applicationName: 'lists.lists'
            automaticOrientation: true
        
            width: units.gu(45)
            height: units.gu(75)
        
            function addtolistView(){
                listView.append({sender: "First Row Added", title: "Add"})
            }
        
            ListView {
                id: listView
                anchors.fill: parent
                model: ListModel {
                    ListElement { sender: "Bob Bobbleton"; title: "How are you going?" }
                    ListElement { sender: "Rug Emporium"; title: "SALE! All rugs MUST go!" }
                    ListElement { sender: "Electric Co."; title: "Electricity bill 15/07/2016 overdue" }
                    ListElement { sender: "Tips"; title: "Five ways this tip will save your life" }
                }
                delegate: SwipeDelegate {
                    id: swipeDelegate
                    text: model.sender + " - " + model.title
                    width: parent.width
        
        
        
                    ListView.onRemove: SequentialAnimation {
                        PropertyAction {
                            target: swipeDelegate
                            property: "ListView.delayRemove"
                            value: true
                        }
                        NumberAnimation {
                            target: swipeDelegate
                            property: "height"
                            to: 0
                            easing.type: Easing.InOutQuad
                        }
                        PropertyAction {
                            target: swipeDelegate
                            property: "ListView.delayRemove"
                            value: false
                        }
                    }
        
                    onClicked: {
                        swipe.complete=false
                    }
        
                    swipe.right: Label {
                        id: deleteLabel
                        text: qsTr("Delete")
                        color: "white"
                        verticalAlignment: Label.AlignVCenter
                        padding: 12
                        height: parent.height
                        anchors.right: parent.right
        
                        SwipeDelegate.onClicked: listView.model.remove(index)
        
                        background: Rectangle {
                            color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
                        }
                    }
                }
            }
        
            Button{
                text: "Add"
                onClicked: addtolistView()
            }
        }
        

        Got this error here (TypeError: Property 'append' of object QQuickListView(0x124f560) is not a function)

        How can that be fixed? 🙂

        Thanks for your time

        Best Reagrds
        007fred50

        lduboeufL 1 Reply Last reply Reply Quote 0
        • lduboeufL Offline
          lduboeuf @007fred50
          last edited by lduboeuf

          @007fred50 use append on the model not the listview. e.g: listview.model.append(..)

          0 1 Reply Last reply Reply Quote 0
          • 0 Offline
            007fred50 @lduboeuf
            last edited by

            @lduboeuf thanks it works 🙂

            1 Reply Last reply Reply Quote 0
            • First post
              Last post