When using instances of QML files by directly declaring them, every property
creates a binding. This is explained in the above examples.
This is how you dynamically create components:
var component = Qt.createComponent("Popup.qml");
var popup = component.createObject(parent, {"width": mainWindow.width, "height": mainWindow.height});
When the size of the mainWindow
changes, the size of the created PopUp
is not affected. To create a binding you set the size of the popup
like this:
var component = Qt.createComponent("Popup.qml");
var options = {
"width": Qt.binding(function() { return mainWindow.width }),
"height": Qt.binding(function() { return mainWindow.height }),
};
var popup = component.createObject(parent, options);
Now the size of the PopUp
will depend on mainWindow
.