Model View of QList<QObject*>of QAbstractListModel



  • I'm attempting to build a model inside a model and I'm not getting expected results. I'm putting a QObject with an invokable function called "get_models". This returns a QList<QObject*>. The list is populated with objects that derive from QAbstractListModel. The first repeater appears to work correctly. It calls the model_name invokable on my derived QAbstractListModel object. The unexpected results occur when I try to create a Repeater from the derived QAbstractListModel. It doesn't appear to recognize it as a model. When I print out the record numbers, it only states 1 for each model I pass in. When I provide the derived QAbstractListModel directly from the provider, rather than as a list, it returns the correct number of records.

    I'm guessing that when it's being handled by the inner repeater it's getting treated as "An Object Instance" instead of a QAbstractListModel object. Does this sound likely? Is there anything I can prove or disprove this? Also is there a work around or a better way of doing this?

    For example:

    @
    Column {
    height: 400
    width: 600
    Text { text: "Models" }

    Repeater {
    id: r1
    model: provider.get_models()
    delegate: Column {
    Text { text: "Model: " + modelData.model_name }
    Repeater {
    id: r2
    model: modelData
    Text { text: "Record Count " + r2.count }
    }
    }
    }
    }
    @

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • This is post is not valid. I was passing in a QSharedPointer< QAbstractListModel > instead of just a QAbstractListModel*.

    This begs another question. After searching I didn't see any direct support in QML to handle QSharedPointer wrapped QObjects. Is this correct or did I miss something. If there isn't direct support. Any ideas?



  • No, there isn't QSharedPointer wrapped QObjects direct support in QML, as I know.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.