[Interest] QML id as string?

Jérôme Godbout godboutj at amotus.ca
Thu Oct 4 15:26:55 CEST 2018


That would be a nice addition, have you try to see if the QQmlContext can
still resolve a QQmlExpression http://doc.qt.io/qt-5/qqmlexpression.html
with the given id? Maybe there would be a way to recover the ids form the
context somehow and kind of reverse find the ids until you find your match
into the actual context.

All QObject have his QQmlContext that can be recover with the QQmlEngine:
http://doc.qt.io/qt-5/qqmlengine.html#contextForObject

not sure it is possible, but it could worth an investigation to see if
something can be extracted from there.

if you ever choose to accept this mission, we would like to have your
finding on the subject ;-)
Jerome


On Thu, 4 Oct 2018 at 08:23, Jason H <jhihn at gmx.com> wrote:

> Thanks Jérôme.
>
> It would be important to note, that what I am trying to do would be
> subject to a few (reasonable) caveats. It's not a find-anything-anywhere,
> definitely-uniique-id, it would be an approach that can be leverage if the
> situation makes it possible to get objects by id, rather than having to
> maintain it myself. This mapping already exists at some level, I just want
> it exposed.
>
> *Sent:* Wednesday, October 03, 2018 at 1:31 PM
> *From:* "Jérôme Godbout" <godboutj at amotus.ca>
> *To:* morten at winkler.dk
> *Cc:* "Qt Interest" <interest at qt-project.org>
> *Subject:* Re: [Interest] QML id as string?
> In that example, the Repeater create a new context (QQmlContext
> http://doc.qt.io/qt-5/qqmlcontext.html ) per instance of the
> QQmlComponent. That context inherite the context of the repeater. But your
> Component.onCompleted is the same context as the Repeater but doesn't have
> the context of the repeated childs. This is why it cannot find the myText
> id and that why each child (with their own context) id can be used without
> crosstalk with each others.
>
> Side note: You can create your own object creation with Component as input
> property and generating the QQmlContext and the Component instance into it
> and make a new kind of repeater (I did myself a map of component and list
> of name that generate different kind of object that way
> (FactoryInstanciator).
>
>
> On Wed, 3 Oct 2018 at 13:26, Morten W. J. <morten at winkler.dk> wrote:
>
>> On onsdag den 3. oktober 2018 19.01.33 CEST Jason H wrote:
>> > The lexical scoping rules are clear,
>>
>> What would you expect to be the output of the below?
>>
>> import QtQuick 2.9
>> import QtQuick.Window 2.2
>>
>> Window {
>>     visible: true
>>     width: 640
>>     height: 480
>>     title: qsTr("Hello World")
>>
>>
>>     Column {
>>         Repeater {
>>             model: 10
>>             Text { id: myText; text: "I'm item " + index }
>>         }
>>         Text { id: last; text: "Last"}
>>     }
>>
>>     Component.onCompleted:
>>     {
>>         console.log(myText.text);
>>         console.log(last.text);
>>     }
>> }
>>
>> On my machine, the output is
>>         qrc:/main.qml:21: ReferenceError: myText is not defined
>> which is a great example on why you cannot rely on id's as item names.
>> The id is only unique at type time.
>>
>>
>> Cheers,
>>    Morten
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> --
>
>
>
>
> RAPPROCHEZ LA DISTANCE
>
> *Jérôme Godbout*
> Senior Software Developer
>
> *p:* +1 (418) 800-1073 ext.:109
>
> *m:* +1 (581) 777-0050
>
> amotus.ca <http://www.amotus-solutions.com/>
> statum-iot.com
>
>
> _______________________________________________ Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>


-- 



RAPPROCHEZ LA DISTANCE


*Jérôme Godbout*Senior Software Developer

*p:* +1 (418) 800-1073 ext.:109

*m:* +1 (581) 777-0050

amotus.ca <http://www.amotus-solutions.com/>
statum-iot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181004/4c914431/attachment.html>


More information about the Interest mailing list