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. Scope trouble. Accessing propeties out of scope.
Forum Updated to NodeBB v4.3 + New Features

Scope trouble. Accessing propeties out of scope.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 382 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.
  • R Offline
    R Offline
    RobM
    wrote on last edited by RobM
    #1

    Let's say I have the following situation:

    Rectangle
    {
      id: recOne
      
      property bool isRed: false
      
      color: isRed ? "red" : "blue"
    }
    
    Item
    {
      id: someItem
      
      Rectangle
      {
        id: recTwo
      
        property bool isRed: recOne.isRed
      
        color: isRed ? "red" : "blue"
      }
    }
    
    

    Now let's say I want to wrap the first Rectangle in a Component like so:

    Component
    {
      id: component_recOne
      
        Rectangle
      {
        id: recOne
      
        property bool isRed: false
      
        color: isRed ? "red" : "blue"
      }
    }
    

    I realize that I can create some alias for the loader of this component and access it's item in order to see the Loader's item properties but what if I need to access recOne properties when it is not currently the active source component of the loader? For instance, what if the loader will have many other components outside of just recOne but recTwo will always need to know what color to be reguardless of what the Loader's current active component is? Wrapping recOne in a Component like that takes it's properties out of scope for recTwo. How do I bring them back into scope?

    fcarneyF 1 Reply Last reply
    0
    • R RobM

      Let's say I have the following situation:

      Rectangle
      {
        id: recOne
        
        property bool isRed: false
        
        color: isRed ? "red" : "blue"
      }
      
      Item
      {
        id: someItem
        
        Rectangle
        {
          id: recTwo
        
          property bool isRed: recOne.isRed
        
          color: isRed ? "red" : "blue"
        }
      }
      
      

      Now let's say I want to wrap the first Rectangle in a Component like so:

      Component
      {
        id: component_recOne
        
          Rectangle
        {
          id: recOne
        
          property bool isRed: false
        
          color: isRed ? "red" : "blue"
        }
      }
      

      I realize that I can create some alias for the loader of this component and access it's item in order to see the Loader's item properties but what if I need to access recOne properties when it is not currently the active source component of the loader? For instance, what if the loader will have many other components outside of just recOne but recTwo will always need to know what color to be reguardless of what the Loader's current active component is? Wrapping recOne in a Component like that takes it's properties out of scope for recTwo. How do I bring them back into scope?

      fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @RobM said in Scope trouble. Accessing propeties out of scope.:

      How do I bring them back into scope?

      <loaderid>.item.<property>

      C++ is a perfectly valid school of magic.

      R 1 Reply Last reply
      0
      • fcarneyF fcarney

        @RobM said in Scope trouble. Accessing propeties out of scope.:

        How do I bring them back into scope?

        <loaderid>.item.<property>

        R Offline
        R Offline
        RobM
        wrote on last edited by
        #3

        @fcarney That's what I was trying to say in my first post. Calling the <loaderid>.item.<property> works if the loader always has that component loaded but not otherwise. I was hoping there was a simple way to gain access to a components properties without accessing the loader.

        fcarneyF 1 Reply Last reply
        0
        • R RobM

          @fcarney That's what I was trying to say in my first post. Calling the <loaderid>.item.<property> works if the loader always has that component loaded but not otherwise. I was hoping there was a simple way to gain access to a components properties without accessing the loader.

          fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          @RobM
          I am very confused. If the component is not loaded it doesn't exist, at all. Loader creates an instance.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            Are you wanting the Rectangle to exist when not visible or the data? If its the latter then take a data driven approach rather than messing with Items. You can build a ListModel in QML with your data and access the data inside that. Then it is primed to be used with various views.

            C++ is a perfectly valid school of magic.

            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