I have a tab view and trying to add the same tab dynamically using a button.
However the second time, QML complains with "qrc:///main.qml:43: TypeError: Type error"

main.qml
Qt Code:
  1. import QtQuick 2.2
  2. import QtQuick.Controls 1.1
  3. import QtQuick.Layouts 1.1
  4.  
  5. ApplicationWindow {
  6. visible: true
  7. width: 640
  8. height: 480
  9. title: qsTr("Hello World")
  10. signal tabAdded(variant c)
  11.  
  12. ListModel {
  13. id: toolbarModel
  14.  
  15. ListElement {
  16. partColor: "red"
  17. }
  18. ListElement {
  19. partColor: "blue"
  20. }
  21. }
  22.  
  23. ColumnLayout{
  24. anchors.fill: parent
  25.  
  26. TabView{
  27. visible: true
  28. id:tabview
  29. Layout.fillHeight: true
  30. Layout.fillWidth: true
  31.  
  32. }
  33. Button{
  34. text: "add tab"
  35. onClicked:{
  36.  
  37. console.log("Component.onCompleted " + toolbarModel.get(0).name)
  38.  
  39. var t = tabview.addTab("tab", Qt.createComponent("TabItem.qml"));
  40. console.log("Component.onCompleted b " + t)
  41. if(t != null)
  42. {
  43. t.item.partsModel = toolbarModel
  44. var last = tabview.count-1;
  45. tabview.getTab(last).active = true;
  46. console.log(tabview.getTab(last).item);
  47. }
  48. }
  49. }
  50. Button{
  51. text: "remove tab"
  52. onClicked:{
  53.  
  54. var last = tabview.count-1;
  55. tabview.getTab(last).active = false;
  56. console.log(tabview.getTab(last).item);
  57. tabview.removeTab(last)
  58. }
  59. }
  60. }
  61.  
  62. }
To copy to clipboard, switch view to plain text mode 

TabItem
Qt Code:
  1. import QtQuick 2.0
  2.  
  3. import QtQuick.Controls 1.1
  4.  
  5. Item{
  6. signal tabButtonClicked()
  7.  
  8. property alias partsModel:parts.partList
  9.  
  10. anchors.fill: parent
  11. Rectangle{
  12. id:colorRect
  13. height: 100
  14. width: 100
  15. z:23
  16. anchors.top : parent.top
  17. color: "red"
  18. }
  19.  
  20. PartList{
  21. id : parts
  22. anchors.left:colorRect.right
  23. z:25
  24. }
  25. }
To copy to clipboard, switch view to plain text mode 

Partlist
Qt Code:
  1. import QtQuick 2.0
  2.  
  3. Item {
  4.  
  5. property var partList
  6.  
  7. ListView{
  8. model:partList
  9. height: 200
  10. width: 100
  11. delegate: delegateComp
  12. }
  13.  
  14. Component{
  15. id: delegateComp
  16. Rectangle{
  17. id: rect
  18. height: 25
  19. width: 25
  20. color: partColor
  21.  
  22. MouseArea{
  23. anchors.fill: parent
  24. onClicked: {
  25. console.log("Color " + partColor)
  26. }
  27. }
  28. }
  29. }
  30. }
To copy to clipboard, switch view to plain text mode 

Kindly advice what step I'm missing