Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89653

read of computed properties needs to read from QObjectComputedProperty object

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P1: Critical P1: Critical
    • None
    • 6.0.0, 6.0
    • Core: Object Model
    • None

      New bindable properties build a dependency graph when bindings are executed. For this to work, there are some magic classes which execute some logic when being read.
      All those magic classes, i.e. QProperty<T>, QObjectBindableProperty, and QObjectComputedProperty, when being read, they do the following: They check whether there is currently a binding evaluated (there is a thread-global object to store that) and if there is a binding currently being evaluated, they conclude they are a dependency of that binding and install an "observer". So in the future, when they change, they will notify this observer.
      For this to work, it is required that the read actually happens from one of those magic objects.

      This implies that the READ function for a computed property has to read from the underlying QObjectComputedProperty, otherwise dependency handling does not work.
      I got this wrong first when porting QItemSelectionModel, so this implementation of "hasSelection" did not work:
      https://codereview.qt-project.org/c/qt/qtbase/+/327044/2

      I had to rename "hasSelection" to "hasSelectionActualComputation", use that as the computation function for the Q_OBJECT_COMPUTED_PROPERTY and create a new "hasSelection" to read from the computed property object.

      Same problem exists with "isActive()" in
      https://codereview.qt-project.org/c/qt/qtbase/+/326654/2
      and with "activeThreadCount()" in
      https://codereview.qt-project.org/c/qt/qtbase/+/326626/8/
      .

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            fabiankosmale Fabian Kosmale
            andreasbuhr Andreas Buhr
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes