[Development] Perceptions/Understandings of the QML language [was: Question about Qt's future]

Alan Alpert 416365416c at gmail.com
Wed Apr 30 23:25:13 CEST 2014


On Tue, Apr 29, 2014 at 11:32 PM, Rutledge Shawn
<Shawn.Rutledge at digia.com> wrote:
>
> On 29 Apr 2014, at 7:51 PM, Alan Alpert wrote:
>
>>> (3) Document that accessing ids from other .qml files without any interface (just relying on the fact that they are in the context) creates hard to maintain QML code.
>>
>> Agreed (honestly, it should already be there, I guess
>> https://bugreports.qt-project.org/browse/QTBUG-20453 was never
>> finished...).
>>
>> Again, we have some rough plans for a ".pragma strict". Which should ban this.
>
> What exactly do you want to ban and what are the best alternatives?  "Without any interface" implies there is a right way to share.

Correct answer: Define an interface. Probably best explained via the
attached examples: "Bad" has no interface defined for the object
reference, "Good" does.

Runner up: Singletons. When you can't or don't want to pass references
to individual object instances, you can pass it to a shared interface
instance and use that. Which is QML singletons, and is fairly
convenient already (though there are known issues like QTBUG-34418
which can make it less convenient than it should).

Workaround: Shared JS file. Does most of the same stuff as the
singleton (biggest exception: QTBUG-21844 ), and is available in
earlier versions. Should singletons be available, use them instead as
they have the declarative and typed interface benefits.

> In practice I'm often not sure about the scoping rules, so when something that I think should be accessible is not, I'm often not sure if that is a bug but just start looking for another way to do it (which sometimes can be clumsy).

If an id is not in file scope, then it's either a bug or an ugly
hidden feature that we keep around for convenience but you aren't
supposed to use ;) .

--
Alan Alpert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BadUser.qml
Type: text/x-qml
Size: 71 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140430/5b431ccd/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GoodUser.qml
Type: text/x-qml
Size: 101 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140430/5b431ccd/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mainBad.qml
Type: text/x-qml
Size: 146 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140430/5b431ccd/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mainGood.qml
Type: text/x-qml
Size: 170 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140430/5b431ccd/attachment-0003.bin>


More information about the Development mailing list