qtdynamicqmlstacklayout

Dynamically add item to StackLayout


I have create an item in a file called NetworkSheet. My other QML file (A.qml) contains a StackLayout (id tabStack) and I would like to add NetworkSheet onto the back of the stack.

I'm going in circles due to a couple of incomplete examples. Can someone suggest how to do this? THe closest I got is:

var stackItem = Qt.createQmlObject('import "../tabs"; NetworkSheet{}', tabStack);
tabStack.children.push(stackItem);

but there is no push method for tabStack's children.


Solution

  • There is no need to append/insert the newly created Item onto the StackLayout. By specifying the parent (as the StackLayout) during creation it automatically gets appended onto the end. So just this line is needed:

    var stackItem = Qt.createQmlObject('import "../tabs"; NetworkSheet{}', tabStack);