pmf
pmf

Reputation: 7749

QML: object instantiation

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.

Upvotes: 0

Views: 504

Answers (1)

eyllanesc
eyllanesc

Reputation: 244132

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

Upvotes: 1

Related Questions