Hi again!
I am trying on something similar to this post [qt-project.org].
I also want to add/remove tabs in qml by pressing buttons and am somehow stuck. My code so far:
main.qml:
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
ApplicationWindow{
id:win
toolBar: ToolBar{
RowLayout{
ToolButton{
text: "addTab"
onClicked: tb.loadTab()
}
ToolButton{
text: "removeTab"
onClicked:tb.removeTab()
}
}
}
TabView{
id:tb
anchors.fill:parent
function loadTab(){
var t=tb.addTab("x",myComponent)
}
function removeTab(){
tb.removeTab(1)
}
}
}
myComponent.qml:
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
GridLayout {
id: id_gridLayout
anchors.fill: parent
Layout.rowSpan: 2
columns: 3
Button { text: "prev" }
Button { text: "next" }
Slider { Layout.fillWidth: true }
Text { text: "asdf" }
Button { text: "prev" }
Button { text: "next" }
Text {
text: "asdf"
Layout.columnSpan: 2
}
Slider { Layout.fillWidth: true }
}
It compiles and I don’t get any warnings, unless I hit the buttons:
addTab: “ReferenceError: myComponent is not defined”
removeTab: “RangeError: Maximum call stack size exceeded.”
Do you have some hints/code snippets for me? Any help is greatly appreciated!
↧