0

Is there a way to have a mechanism similar to Component.createObject's second argument (initial properties) with a Loader element? I'm setting the properties manually in onLoaded, but this has slightly different semantics.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
pmf
  • 7,619
  • 4
  • 47
  • 77

1 Answers1

1

Use setSource():

// example.qml
import QtQuick 2.0
Item {
    Loader {
        id: squareLoader
        onLoaded: console.log(squareLoader.item.width);
        // prints [10], not [30]
    }

    Component.onCompleted: {
        squareLoader.setSource("ExampleComponent.qml",
                             { "color": "blue" });
        // will trigger the onLoaded code when complete.
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241