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

Support reading id property

    XMLWordPrintable

Details

    • All

    Description

      The id property is a special property:
      Item

      { id: myItem name: "myItem" }

      An instance my have more than one id, depending on context. QString "QQmlContext::nameForObject(QObject *object) const
      Returns the name of object in this context, or an empty string if object is not named in the context. Objects are named by setContextProperty(), or by ids in the case of QML created contexts. If the object has multiple names, the first is returned."

      It is advantageous at times to be able to reference objects by id. However this is not possible in QML. The Item's data property can be used to enumerate children:
      for (var c=0; c< data.length; c++)

      { console.log(c, data[c].name); }

      However the above code only works because "name" is an assigned property. Ideally I would not have to maintain a name property identical to the id property and could just do:
      console.log(c, data[c].id);
      instead.

      I don't understand why / I am requesting that the id property be accessible as a read-only string, giving the first name in the context of the containing item (parent). Or a potential compromise is to soft-assign a 'name' property to be id, unless otherwise set.

      This would enable QML code to look up items by using a string name (id), enabling additional scripting and introspection.

      Attachments

        Issue Links

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

          Activity

            People

              shausman Simon Hausmann
              scorp1us Jason Hihn
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes