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. Strange qml property evaluation behaviour
Forum Updated to NodeBB v4.3 + New Features

Strange qml property evaluation behaviour

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 315 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
    Danix
    wrote on last edited by
    #1

    Hello guys, I have the following QtQuick snippet showing behavior I don't quite understand:

    import QtQuick 2.5
    
    Rectangle {
    id: rect
    width: 300
    height: 300
    property int property1: height
    property int property2: width
     Rectangle {
        height: rect.property1
        width: {
         console.log("rect width is ", rect.property2); 
         return rect.property2;
        }
      }
    }
    

    So, I am binding rect.property2 to rect.width which is 300. I would expect the console log to appear once saying "rect width is 300", but it is output twice: "rect width is 0" and "rect width is 300". As a user, based on the above code I am not expecting rect.width to be zero (this behaviour is actually breaking the logic in my current project). But if I comment out the line "height: rect.property1" I see the expected output . Any ideas how to explain this?

    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