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

Document that internal contexts are readonly

    XMLWordPrintable

Details

    Description

      qmlContext(object) returns the internal context of an object which is a QQmlContext. When calling {{setContextproperty()} on such a context object, the user gets an error message "QQmlContext: Cannot set property on internal context".

      1. It is not documented that objects have an internal context and that this context is not writable. Thus, the behavior is surprising. At least, it should be documented.
      2. The returned context object is almost useless if it is read-only. There are situations where one needs to set context properties for specific objects. See below.

      A {
          B {
              name: "blah"
              property string someProperty: "someValue"
          }
      
          B {
              name: "blub"
              RelatesTo { name: "blah" } // object blah is supposed to be attached as context property
              property string xz: blah.someProperty
          }
      }
      

      In above example, the RelatesTo item makes the "blah" instance of B available in the "blub" instance. This is kind of similar to the Depends item in Qbs and happens after the Component::beginCreate() and before bindings are evaluated. But it is currently not possible because the "internal" context of each object is not writable and QObject::setProperty() has no effect.

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            rweickelt Richard Weickelt
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes