Accessing either one of two components



  • 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



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

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

    ?



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.