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?

1 Answer 1

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
                }
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.