I'm trying to dynamically create Tab
s in QML. The code below is a simple example of what I want to do.
import QtQuick 2.0
import QtQuick.Controls 1.0
ApplicationWindow{
id:win
TabView{
id:tb
anchors.fill:parent
MouseArea{
anchors.fill:parent
onClicked:tb.loadTab()
}
Component{
id:viewComp
Rectangle{
anchors.fill:parent
color:"black"
}
}
function loadTab(){
var t=addTab("x",viewComp)
t.item.color="blue" //line 20
}
}
}
Addition of the first Tab
works as expected. However, after that any other Tab
added triggers the error:
TypeError: Cannot set property 'color' of null`.
I tried to access the Tab
with getTab()
to change the color, but I get the same error. Can someone explain what am I doing wrong?