Details
-
Suggestion
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
5.11.2
-
None
Description
The id property is a special property:
Item
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++)
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
- duplicates
-
QTBUG-18554 Object (component) string id not accessible by users
- Closed
- relates to
-
QTBUG-6580 id sometimes sets objectName
- Closed
-
QTBUG-7183 id is only set if there are quotes around the id in QML source.
- Closed