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. Can't get parent property value in if statement
Forum Updated to NodeBB v4.3 + New Features

Can't get parent property value in if statement

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 511 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.
  • D Offline
    D Offline
    Deyan
    wrote on last edited by Deyan
    #1

    I can't reach parent properties inside if statement and if condition .Properties from another qml items passed by id can't be read too. Here is the code:
    Image {

        id: myImage
        antialiasing: true
        x: xCoordinate
        y: yCoordinate
        width: elementWidht
        height: elementHeight
        rotation: rotationAngle
        fillMode: cellFill
        smooth: cellSmooth
    
        source: "qrc:/pics/folder/Frame.svg"
    
        property string cname: "myImage"
    
        Component.onCompleted: {
            console.log(cname, "successfully created!");
        }
    
        //print caption
        property alias text3: caption.text
    
    
             Text {
                 horizontalAlignment: Text.AlignHCenter
                 verticalAlignment: Text.AlignVCenter
                 id: caption
                 //width: parent.width
                 height: 29
                 color: "red"
                 text: "dynamically changed text..."
                 font.pointSize: 9
                 rotation: 360- parent.rotation  //here parent rotation is 270
               anchors.top: {if(parent.rotation ==180) {parent.top
                   console.log("here1")}
                    if(parent.rotation==0){parent.bottom // parent rotation is null here and go into if statement?
                    console.log("here2" + parent.rotation) //gives null
                    }
    
                    if(parent.rotation==90){parent.right
                    console.log("here3")
                    }
    
                }
    }
    

    }

    J.HilkJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @Deyan ah ok, I now see this is inside the anchors property.
      Possible, that is messing things up! Because a local scope shouldn't mess this up.

      You can always refer to the item directly via the id, caption or myImage

      D Offline
      D Offline
      Deyan
      wrote on last edited by
      #5
      This post is deleted!
      1 Reply Last reply
      0
      • D Deyan

        I can't reach parent properties inside if statement and if condition .Properties from another qml items passed by id can't be read too. Here is the code:
        Image {

            id: myImage
            antialiasing: true
            x: xCoordinate
            y: yCoordinate
            width: elementWidht
            height: elementHeight
            rotation: rotationAngle
            fillMode: cellFill
            smooth: cellSmooth
        
            source: "qrc:/pics/folder/Frame.svg"
        
            property string cname: "myImage"
        
            Component.onCompleted: {
                console.log(cname, "successfully created!");
            }
        
            //print caption
            property alias text3: caption.text
        
        
                 Text {
                     horizontalAlignment: Text.AlignHCenter
                     verticalAlignment: Text.AlignVCenter
                     id: caption
                     //width: parent.width
                     height: 29
                     color: "red"
                     text: "dynamically changed text..."
                     font.pointSize: 9
                     rotation: 360- parent.rotation  //here parent rotation is 270
                   anchors.top: {if(parent.rotation ==180) {parent.top
                       console.log("here1")}
                        if(parent.rotation==0){parent.bottom // parent rotation is null here and go into if statement?
                        console.log("here2" + parent.rotation) //gives null
                        }
        
                        if(parent.rotation==90){parent.right
                        console.log("here3")
                        }
        
                    }
        }
        

        }

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @Deyan probably a transformation/cast error, try

        console.log("here2", parent.rotation) instead of console.log("here2" + parent.rotation)


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        D 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @Deyan probably a transformation/cast error, try

          console.log("here2", parent.rotation) instead of console.log("here2" + parent.rotation)

          D Offline
          D Offline
          Deyan
          wrote on last edited by
          #3

          @J-Hilk I tried but again the value is 0. It is 0 inside if condition too, because console.log wouldn't be reached if parent.rotation was read correctly.

          J.HilkJ 1 Reply Last reply
          0
          • D Deyan

            @J-Hilk I tried but again the value is 0. It is 0 inside if condition too, because console.log wouldn't be reached if parent.rotation was read correctly.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @Deyan ah ok, I now see this is inside the anchors property.
            Possible, that is messing things up! Because a local scope shouldn't mess this up.

            You can always refer to the item directly via the id, caption or myImage


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            D 2 Replies Last reply
            1
            • J.HilkJ J.Hilk

              @Deyan ah ok, I now see this is inside the anchors property.
              Possible, that is messing things up! Because a local scope shouldn't mess this up.

              You can always refer to the item directly via the id, caption or myImage

              D Offline
              D Offline
              Deyan
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @Deyan ah ok, I now see this is inside the anchors property.
                Possible, that is messing things up! Because a local scope shouldn't mess this up.

                You can always refer to the item directly via the id, caption or myImage

                D Offline
                D Offline
                Deyan
                wrote on last edited by
                #6

                @J-Hilk Thanks you are 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