title: How are QML property dependencies determined? (and how to manipulate them)
body: <p>A property that is bound to an expression is updated when something in the expression changes.
  This is called <em>a dependency</em>.</p>
  <p>EDIT:</p>
  <blockquote>
  <p>To clarify:</p>
  <ul>
  <li>I'm interested in details on how Qt determines a list of dependencies</li>
  <li>Dependencies on simple bindings such as <code>x: y</code> are more or less obvious</li>
  <li>The question is about less obvious cases such as <code>x: myItemId[&quot;y&quot;]</code> and <code>x: myFunction(z)</code> where <code>myFunction(p) { if (p) return myItemId.y }</code></li>
  </ul>
  </blockquote>
  <p>Sometimes QML engine is able to detect change even if the expression is a function call without arguments, other times it cannot do that (for example mapToItem(item,0,0).x).</p>
  <p>Another example of imperfection is that <a href="https://stackoverflow.com/questions/19583234/qml-binding-to-an-array-element/19653693">setting JS array item value without reassigning the array itself</a> doesn't normally produce onXxxxxChanged signal or update anything referring to that array value.</p>
  <p>An expression with unused result (<code>x: {myForcedDependency; return myActualCalculation()}</code>) is sometimes <a href="https://stackoverflow.com/questions/44921549/how-to-tell-a-qml-binding-about-additional-dependencies">suggested to force a dependency</a>.</p>
  <p>According to <a href="https://www.kdab.com/qml-engine-internals-part-2-bindings" rel="nofollow noreferrer">this KDAB article</a> and <a href="https://code.woboq.org/qt5/qtdeclarative/src/qml/qml/qqmljavascriptexpression.cpp.html#_ZN19QQmlPropertyCapture15capturePropertyEP12QQmlNotifier" rel="nofollow noreferrer">Qt source code</a>, a binding expression is not only evaluated but any properties &quot;accessed&quot; during that are &quot;captured&quot; in something called a &quot;guard&quot;, then every guard properties onXxxxxChanged() signals are connected, but actual details of this process are unclear.</p>
  <p>So my questions are:</p>
  <ul>
  <li><p>Are there any defined rules of dependency resolution?</p>
  </li>
  <li><p>How does it really work?</p>
  <ul>
  <li>How deeply does QQmlEngine/V8 scan &quot;accesses&quot; into functions called by the binding expression and what may prevent it from doing that?</li>
  <li>Is dependency-detection only based on the first attempt at property resolution?</li>
  <li>Are all possible code paths checked even if execution never reached there yet?
  <ul>
  <li>Are non-trivial accesses determined in those cases, such as object[&quot;property&quot;] syntax?</li>
  <li>What if some unexecuted code is (currently) erroneous (and does not produce an error but cannot be properly analyzed)?</li>
  </ul>
  </li>
  </ul>
  </li>
  <li><p>How can the dependency resolution process be influenced?</p>
  <ul>
  <li>Is there a way to avoid or block a dependency?
  <ul>
  <li>As far as I understand an intermediate &quot;filter&quot; property that only actually changes its value when it's necessary to update is the intended way, correct?</li>
  </ul>
  </li>
  <li>Is there an intended way to force a dependency?
  <ul>
  <li>Is manually emitting &quot;XxxxxChanged&quot; signal the correct/supported way to force an update?</li>
  <li>Is adding an unused reference a legal/intended way to do it or undefined behavior based on the current implementation quirk?</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p>Any information would be useful, although I did read the official documentation on QML properties, QML bindings and JavaScript expressions and didn't find any concrete explanation - if you refer to the official documentation please quote relevant parts.</p>
  <p>Please note that I'm not asking you to test if any of this works on your system, but if it's <em>supposed</em> to work - if it can be relied on</p>