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

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login