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. properties of a component loaded by TabView
Forum Updated to NodeBB v4.3 + New Features

properties of a component loaded by TabView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.3k 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.
  • redouaneR Offline
    redouaneR Offline
    redouane
    wrote on last edited by redouane
    #1

    i have the issue where the height value is 0 if i read it right after the loading.
    here is my code

    void foo(){
    do stuf...
    
    finishCreation();
    
    do stuf....
    }
    
    Component{
                   id: someId
                   Rectangle{
                       anchors.fill:parent
                       color:"red"
    
                   property int val1:2
                   property int val2:3
                   function getValues(){
                       return val1+val2
                   }
                   }
               }
    Timer{
                id : myTimer
                running: false
                repeat: false
                interval: 1//milli seconde
                onTriggered: {
                        console.log("from timer",mainTabView.getTab(4).item.height);
                }
            }
        function finishCreation(){
            var tabComponant = Qt.createComponent("qrc:/gui/qmlui/qml.qml");
            var tab = mainTabView.addTab("main",someId)
            tab.loaded.connect(fullyLoaded)
            tab.active = true;
           // tab.item.update() // useless
          // mainTabView.update() // useless
           console.log("calling the function ",mainTabView.getTab(4).item.getValues()) // this call return the right values of properties
            console.log("right after creation",mainTabView.getTab(4).item.height);// index 4, represent this added tab
            myTimer.running = true;// activate the timer
        }
    function fullyLoaded(){ // here we are sure that every thing is loaded and still print 0
            console.log("fully loaded",mainTabView.getTab(4).item.height);
        }
    

    the result of console.log() in order of execution:
    fully loaded 0
    calling the function 5 // right ;)
    right after creation 0
    from timer 512

    my guessing is that the timer is executed by the event loop, and at that point every thing is ready.
    my question, is how to access the component properties(height width) right after creating them and/or adding them to the TabView. (using a timer is a poor implementation)

    p3c0P 1 Reply Last reply
    0
    • redouaneR redouane

      i have the issue where the height value is 0 if i read it right after the loading.
      here is my code

      void foo(){
      do stuf...
      
      finishCreation();
      
      do stuf....
      }
      
      Component{
                     id: someId
                     Rectangle{
                         anchors.fill:parent
                         color:"red"
      
                     property int val1:2
                     property int val2:3
                     function getValues(){
                         return val1+val2
                     }
                     }
                 }
      Timer{
                  id : myTimer
                  running: false
                  repeat: false
                  interval: 1//milli seconde
                  onTriggered: {
                          console.log("from timer",mainTabView.getTab(4).item.height);
                  }
              }
          function finishCreation(){
              var tabComponant = Qt.createComponent("qrc:/gui/qmlui/qml.qml");
              var tab = mainTabView.addTab("main",someId)
              tab.loaded.connect(fullyLoaded)
              tab.active = true;
             // tab.item.update() // useless
            // mainTabView.update() // useless
             console.log("calling the function ",mainTabView.getTab(4).item.getValues()) // this call return the right values of properties
              console.log("right after creation",mainTabView.getTab(4).item.height);// index 4, represent this added tab
              myTimer.running = true;// activate the timer
          }
      function fullyLoaded(){ // here we are sure that every thing is loaded and still print 0
              console.log("fully loaded",mainTabView.getTab(4).item.height);
          }
      

      the result of console.log() in order of execution:
      fully loaded 0
      calling the function 5 // right ;)
      right after creation 0
      from timer 512

      my guessing is that the timer is executed by the event loop, and at that point every thing is ready.
      my question, is how to access the component properties(height width) right after creating them and/or adding them to the TabView. (using a timer is a poor implementation)

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      Hi @redouane and Welcome,

      AFAIK that operation is asynchronous since Tab inherits Loader. So by the time you print the height the tab is not yet loaded.
      Try loading a a Tab which has very minimal content to verify the above scenario. You might get the expected height.

      157

      redouaneR 1 Reply Last reply
      0
      • p3c0P p3c0

        Hi @redouane and Welcome,

        AFAIK that operation is asynchronous since Tab inherits Loader. So by the time you print the height the tab is not yet loaded.
        Try loading a a Tab which has very minimal content to verify the above scenario. You might get the expected height.

        redouaneR Offline
        redouaneR Offline
        redouane
        wrote on last edited by
        #3

        @p3c0 said:

        asynchronous

        the documentation said that by default it is synchronous.
        i did modify the code as you said and i did add a function to call (see the new code), calling the function return the right values, so i assume its loaded.

        p3c0P 1 Reply Last reply
        0
        • redouaneR redouane

          @p3c0 said:

          asynchronous

          the documentation said that by default it is synchronous.
          i did modify the code as you said and i did add a function to call (see the new code), calling the function return the right values, so i assume its loaded.

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @redouane Sorry my bad.
          I tried to recreate the same problem with this minimal example. It works as expected.

          import QtQuick 2.5
          import QtQuick.Controls 1.3
          
          Rectangle {
              width: 400
              height: 400
          
              Component{
                  id: someId
                  Rectangle{
                      anchors.fill:parent
                      color: '#'+Math.floor(Math.random()*16777215).toString(16);
                  }
              }
          
              TabView {
                  id : mytab
                  anchors.fill: parent
              }
          
              Button {
                  id: btn
                  anchors.bottom: parent.bottom
                  text: "Add new tab"
                  onClicked: {
                      var tab = mytab.addTab(mytab.count+1,someId)
                      mytab.currentIndex = mytab.count-1
                      
                      console.log(mytab.getTab(mytab.count-1).item.height)
                  }
              }
          }
          

          Can you try it ?

          Also are you sure you are referring the proper index ? i.e 4
          mainTabView.getTab(4).item.height

          157

          1 Reply Last reply
          0
          • redouaneR Offline
            redouaneR Offline
            redouane
            wrote on last edited by redouane
            #5

            yes, if you look in my example, when i call the function getValues() inside the component it return the right value, which means that it is loaded and the index is right.

            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