2

I have a c++ class that i registerd it in qml , and this class have an model that was inherited from QAbstractListModel,Now I want this model with a SwipeView

Manager {
    id: manager
}
SwipeView {
    id: sv           
    model:manager.listModel /// but it don't have model property
}

but SwipView don't havd a model property? How should id add Pages dynamically to thsi swipeview along with this model?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
mohsen
  • 1,763
  • 3
  • 17
  • 55

1 Answers1

4

You can use a Repeater as an example of the docs:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    ListModel{
        id: mymodel
        ListElement{
            name: "name1"
            background: "red"
        }
        ListElement{
            name: "name2"
            background: "salmon"
        }
        ListElement{
            name: "name2"
            background: "gray"
        }
    }
    SwipeView{
        id: view
        anchors.fill: parent
        Repeater{
            model: mymodel
            Rectangle{
                color: model.background
                Text {
                    anchors.centerIn: parent
                    text: model.name
                }
            }
        }
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241