qtqmlqtquick2qt5.3qtquickcontrols

Dynamically loaded QML-file in Tab will only be executed when Tab is shown


I'm creating Tabs in a TabView dynamically via

var component = Qt.createComponent("file://tabcontent.qml"));
tabView.addTab(component);

However their code is not executed before I click on the Tab itself. How can I solve this?


Solution

  • The created Tab inherits from Loader with its active property set to false until the Tab is clicked. Just explicitly set the active property after creating it:

    var component = Qt.createComponent("file://tabcontent.qml'));
    var tab = tabView.addTab(component);
    tab.active = true;