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 warningsthe
main.childrenRect
is actually barely used. It is not being used to anchor anything, and besides thedebugrect
the only other reference to that, which is the actual intended use, is to size the content size of aFlickable
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 differencethe
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 themain.childrenRect
either
QQuickView
on Qt 5.7.0 on Windows 10. I did not get any binding loops when I removed theRectangle
, and I did not get any binding loops when I removed the innerItem
.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.main
properties only, and those are in no way dependent on thedebugrect
object.