Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Dynamically populate Qml TabView .
Forum Updated to NodeBB v4.3 + New Features

[Solved] Dynamically populate Qml TabView .

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 7.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uldisk
    wrote on last edited by
    #1

    I'm trying to dynamically create tabs in Qml. This is my simple example of what I'm trying to do, but the code does not work. Well..sort of doesn't work. It creates the first tab correctly, but throws:
    @ mainWindow.qml:20: TypeError: Cannot set property 'color' of null. @ .

    It seems I'm missing something in adding Tabs. What is wrong?

    @import QtQuick 2.0
    import QtQuick.Controls 1.0

    ApplicationWindow{
    id:win
    TabView{
    id:tb
    Component{
    id:viewComp
    Rectangle{
    anchors.fill:parent
    color:"black"
    }
    }
    anchors.fill:parent
    function loadTab(){
    var t=addTab("x",viewComp)
    t.item.color="blue" //line 20
    }
    MouseArea{
    anchors.fill:parent
    onClicked:tb.loadTab()
    }
    }

    }@

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      The problem is that you are assuming that the "item" is loaded already when you add the tab. The actual creation happens lazily when the tab becomes visible. It works for the first tab since that is already visible when you add it.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        uldisk
        wrote on last edited by
        #3

        Wow... finally some answer. Thanks.

        This should definitely be in some of the TabView or Tab docs IMHO.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qmlLearner
          wrote on last edited by
          #4

          Sorry to reactivate this topic. What was the fix to the above problem? How can you force to component to be created? Thank you very much!

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jens
            wrote on last edited by
            #5

            You can set the active property of the Tab (inherited from Loader) to true. That will force its creation, and the "item" property will be available afterwards.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qmlLearner
              wrote on last edited by
              #6

              Alright...thank you very much!

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved