ListView - append is not a function
-
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 -
@007fred50 use append on the model not the listview. e.g: listview.model.append(..)
-
@lduboeuf thanks it works