1
votes

what is the best way to pass any model (for example a ListModel in main.qml) through loader into an other .qml file?

2

2 Answers

2
votes

If the model only needs to be set once, then you can simply do that in the onLoaded signal handler

Loader {
    id: loader

    source: "myelement.qml"

    onLoaded: item.modelProperty = yourModelId;
}

If it needs to be a binding, e.g. if the model is stored in a property which will change during runtime to a different model instance, then a Binding element should work

Binding {
    target: loader.item
    property: "modelProperty"
    value: theModelStoreProperty
}
1
votes

There is really only one way to use a loader. Pass the url of the qml file to the source property.

From http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-loader.html#details

Loader {
       id: myLoader
       source: "MyItem.qml"
    }

It sounds like this is not quite what you are asking though. If you can provide more details on what you are doing we may be able to provide more help.