[Interest] Best software engineering practices for QML
NIkolai Marchenko
enmarantispam at gmail.com
Tue Sep 24 14:26:33 CEST 2024
> Do you really care? What are you trying to prevent? Why?
It helps prevent brainless leakage of the class implementation into the
using code. Sure, people can still try to find it using workarounds but
they will be that much less inclined to do so. The point about extra object
is pretty valid tho if the path is hot.
On Tue, Sep 24, 2024 at 3:22 PM Pierre-Yves Siret <py.siret at gmail.com>
wrote:
>
> Le mar. 24 sept. 2024 à 13:52, Federico Ferri <federico.ferri.it at gmail.com>
> a écrit :
>
>> Greetings,
>>
>> during last years of development with QML I always wondered how to solve
>> certain software engineering problems.
>>
>> First, defining private properties: I have seen sometimes doing:
>>
>> Item {
>> property int publicProp: 40 + state.privateProp
>> QtObject {
>> id: state
>> property int privateProp: 2
>> }
>> }
>>
>> which seems a rather clever workaround, except for some reason it does
>> not work with QtObject itself (error: Cannot assign to non-existent default
>> property):
>>
>> QtObject {
>> property int publicProp: 40 + state.privateProp
>> QtObject {
>> id: state
>> property int privateProp: 2
>> }
>> }
>>
>> it is possible to do:
>>
>> QtObject {
>> property int publicProp: 40 + _.privateProp
>> property QtObject _: QtObject {
>> property int privateProp: 2
>> }
>> }
>>
>> but it exposes the private QtObject so it kind of defeats its purpose.
>>
>
> I am just answering this first point.
>
> Do you really care? What are you trying to prevent? Why?
> Having an internal object is "clever" as you mentioned but doesn't prevent
> anything and adds yet another object instantiation (and further
> indirection).
> The `state` object in the first Item example can still be accessed with
> `item.resources[0]` by a motivated person.
> Until private properties are implemented in QML, I am just using the
> Python convention for "private" properties. If I want to have a "private"
> property in a QML object, I prefix it with an underscore.
> This documents the property as an internal one that shouldn't be messed
> with.
> External users accessing and modifying will do that at their own expense,
> and no guarantee is made about the consequent behaviour.
>
> In the end it boils down to how you want to access the property in your
> internal code.
> Do you prefer `root._foobar` or `root.internal.foobar`?
>
> Cheers,
> Pierre-Yves
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240924/c63cf702/attachment.htm>
More information about the Interest
mailing list