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. Accessing either one of two components
Forum Updated to NodeBB v4.3 + New Features

Accessing either one of two components

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qt-quickqml bindingqml dynamic
3 Posts 2 Posters 967 Views
  • 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.
  • B Offline
    B Offline
    ben80
    wrote on last edited by
    #1

    Hi,

    What's the preferred way of accessing either one of of two rectangle items?

    I "instantiate" a rectangle component (which contains other rectangles and an image) twice -> idRect1, idRect2.
    Depending on some conditions, that are evaluated in JS i would like to access either one of the rectangles. Then, i need to:

    1. read and set properties
    2. update bindings

    So far i am using code like shown below. This seems to work, but is very prone to weird conditions. My code seems to "overwrite" properties of the not selected component.

    idRectX = idRect1
    idRectX.property1 = 111
    idRectX.anchors.horizontalCenter  = Qt.binding(function() {return idRoot.horizontalCenter})
    

    Thanks for your help,
    Ben

    E 1 Reply Last reply
    0
    • B ben80

      Hi,

      What's the preferred way of accessing either one of of two rectangle items?

      I "instantiate" a rectangle component (which contains other rectangles and an image) twice -> idRect1, idRect2.
      Depending on some conditions, that are evaluated in JS i would like to access either one of the rectangles. Then, i need to:

      1. read and set properties
      2. update bindings

      So far i am using code like shown below. This seems to work, but is very prone to weird conditions. My code seems to "overwrite" properties of the not selected component.

      idRectX = idRect1
      idRectX.property1 = 111
      idRectX.anchors.horizontalCenter  = Qt.binding(function() {return idRoot.horizontalCenter})
      

      Thanks for your help,
      Ben

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @ben80 What happens if you, just for the sake of testing, do something like

      if (...) {
          idRect1.property1 = 111
          ...
      } else {
           idRect2.property1 = 111
          ...
      }
      

      ?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        ben80
        wrote on last edited by
        #3

        Good idea, i will try that as soon as i find some spare time.

        Though, that cannot be the final solution. I would have to copy too much code.
        So, what's the right way of doing it?

        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