0

It's been several times already, so this time I decided to ask and see if anyone has an idea what is going on.

I have this item backbone:

Item {
  id: main
  property alias rw: main.childrenRect.width
  property alias rh: main.childrenRect.height
  property alias rx: main.childrenRect.x
  property alias ry: main.childrenRect.y

  // other stuff here

  Item {
    Rectangle { // debugrect
      width: main.rw
      height: main.rh
      x: main.rx
      y: main.ry
      color: "#00000000"
    }
  }
}

The debugrect served as a visual debug aid, note how it is wrapped in another item at position 0,0 with size 0,0 - that is it is not in any way included in the childrenRect of the main item. Also it doesn't have an id, thus it is not being referenced by any other item whatsoever.

What's most confusing, it is not the presence of this object that causes binding loop messages, but its removal from the code. For some reason, even though it is completely isolated from influencing any other object, removing it causes binding loops in other objects which have absolutely nothing to do with it. What possible mechanic could involve that isolated object's presence in the manifestation of binding loops?

Note: I have not included the full code because it is irrelevant. It is longer than anyone would be willing to debug for me, I have debugged it and found nothing wrong with it, the question is not about "what's wrong with my code" but about "what's wrong with qt" - about how something isolated could be influencing unrelated bindings or triggering false warnings.

Edit: To dispel theories that the debugrect might in some way influence the main.childrenRect, I'd like to offer this:

Logical proof: The debugrect is sized by the main.childrenRect, thus if it influenced it in any way, then that would cause a binding loop. There is no such loop, as there is no such influence. The wrapping Item does influence the main.childrenRect, however, it is a zero size item at position 0,0, and it doesn't move or anything like it, so with or without it, absent any other objects, you'd get a 0,0,0,0 for the main.childrenRect.

Practical proof:

  Item {
    Rectangle {
      width: 10
      height: 10
    }
    Item {
      Rectangle {
        width: 100
        height: 100
      }
    }
    Component.onCompleted: console.log(childrenRect)
  }

The output, as expected, says: QRectF(0, 0, 10, 10) - the inner rectangle does not influence the outer rectangle's childrenRect in any way when it is wrapped in a "null" item.

Also, not that it matters, but the binding loops I am getting are about objects, declared in other sources which have no notion of the debugrect whatsoever.

My preliminary theory is that the presence or absence of the rectangle in question influences in some way the order and structure of the binding evaluation trees (and not the actual results). The code is very complex but it also works just fine, there is no erroneous behavior when the debugrect is removed, debugging has not indicated any actual binding loops taking place, just the warnings of them. Big whoop, some might say, however this application redirects the console output to the user to indicate actual problems and I can't have it flooded by bogus warnings. As the binding logic is quite complex, it seems to hit a weak spot in the binding evaluation implementation, and from earlier detailed tests I have verified that qml bindings are hardly evaluated in the most logical or efficient way. The solution is to simply leave the rectangle there, but out of curiosity, I would like to get to the bottom of this.

Edit 2: Extra info:

  • debugrect having static position and dimension results in the same behavior as removing it altogether. It seems that absent those bindings the qtquick runtime generates the warnings

  • the main.childrenRect is actually barely used. It is not being used to anchor anything, and besides the debugrect the only other reference to that, which is the actual intended use, is to size the content size of a Flickable the main item is in, and to compensate for objects in negative space, since flickable doesn't seem to work with objects in it, it starts at 0,0. The idea here is for the main item to expand the flickable content area to accommodate all of the main item's children. Removing the intended use reference doesn't make a difference

  • the main.childrenRect is not used in any way in any of the objects which generate binding loop warnings, neither directly, nor indirectly. What's more, the objects in question don't influence the main.childrenRect either

22
  • I loaded your backbone code using QtQuick 2.7 in a default QQuickView on Qt 5.7.0 on Windows 10. I did not get any binding loops when I removed the Rectangle, and I did not get any binding loops when I removed the inner Item.
    – JKSH
    Sep 11, 2016 at 16:22
  • It's probably looping through the childrenRect - it's not isolated. In this small example there is no loop, because there are no layouts or grids that stretch with the content. But in your actual code there may be. Don't ask "what's wrong with qt", it's accurate when it comes to binding loops.
    – Velkan
    Sep 11, 2016 at 16:35
  • @JKSH - the binding loops are for other unrelated objects. They bind to the main properties only, and those are in no way dependent on the debugrect object.
    – dtech
    Sep 11, 2016 at 16:41
  • @Velkan - I've been using QML since before it was even officially released, and my observations don't match yours. QML is OK for simple "by the book" things which is what you've been using it for, but as soon as you start doing complex and unorthodox things with it, you are faced by a swarm of bugs and poor design limitations. I have encountered 4 bugs in QML in the last 24 hours alone - object lifetime management, scene-graph visibility, qml compiler and bindings. It might be a good idea to get a good idea before praising Qt, through experience or just see how many critical bugs it has open..
    – dtech
    Sep 11, 2016 at 16:44
  • @ddriver Then please provide an example which triggers the bug. It's hard for us to tell you what's wrong when we can't reproduce the issue.
    – JKSH
    Sep 11, 2016 at 16:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.