SlideshowView with a dynamic model

Hi,

i need some programming help. I have a SlideshowView that uses a VisualItemModel. So far the model is static - which works fine. However, now i need to a have a dynamic model (i basically need to add or remove an Item - depending on the configuration). The question now is - how can i solve this? How can i have a dynamic VisualItemModel - rebuilding the model is possible from a business point of view, but how can i realize that? I could not find any examples handling this problem.

My code basically looks like this. How can i add remove the dividendsColumn depending on a boolean flag?

VisualItemModel {
    id: viewsModel

    Item {
        id: marketdataColumn
        width: viewsSlideshow.width
        height: viewsSlideshow.height

        MarketdataView {
            id: marketdataView
            width: parent.width
            height: parent.height
        }
    }

    Item {
        id: dividendsColumn
        width: viewsSlideshow.width
        height: viewsSlideshow.height

        DividendsView {
            id: dividendsView
            width: parent.width
            height: parent.height
        }
    }
}


SlideshowView {
    id: viewsSlideshow
    model: viewsModel
    onCurrentIndexChanged: {
        openTab(currentIndex)
    }
    Behavior on opacity {
        NumberAnimation {
        }
    }
    onOpacityChanged: {
        if (opacity === 0) {
            slideshowVisibleTimer.start()
        }
    }
}
                

I had not heard of VisualItemModel, before, but this Stackoverflow answer sais what you want is not possible.
They suggest moving to a ListModel and a *View instead.

However, there is also ObjectModel, which supports append() and remove() methods and might be easier to move to.

Look at DelegateModel QML Type, Example, but when you have a lot of items, performance might be disappointing

Even better: use the ObjectModel (import QtQml.Models 2.2) - this can be used as a drop in replacement for VisualItemModel and it provides the api methods to append Objects and clear the model. This finally solved my problem - sometimes it is so easy - you only have to read the documentation.