Вкладка загрузки из другого файла ничего не показывает. QML

Я пытаюсь динамически загружать вкладки в TabView из другого файла. Для этого я использую Qt.createComponent и добавляю компонент в представление. Вкладка загружена, но ее содержимое не отображается и загружено правильно. Нравится:

TabView {
   id:editor
   Layout.minimumWidth: 50
   Layout.fillWidth: true
}

Component.onCompleted: {
    function newTab() {
        var c = Qt.createComponent("tab.qml");
        editor.addTab("tab", c);
        var last = editor.count - 1;
        editor.getTab(last).active = true;
    }

    newTab();
    newTab();
}

И файл tab.qml:

import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4


Tab {
    Rectangle {
        Layout.fillWidth: true
        Layout.fillHeight: true
        color: "lightgray"

        TextArea {
            anchors.fill: parent
        }
    }
}

Что я делаю не так?


person Jerry    schedule 21.12.2015    source источник


Ответы (1)


Прочитав предложение по очистке @folibis, я понял, что обработчик Tab onCompleted не работает. Почему не знаю. Однако замена

var c = Qt.createComponent("tab.qml");
editor.addTab("tab", c);
var last = editor.count - 1;
editor.getTab(last).active = true;

с участием

var c = Qt.createComponent("tab.qml");
var tab = editor.addTab("tab", c);
tab.active = true

решил это.

person Jerry    schedule 21.12.2015