[QBS] [Qt-qml] Is there a QML "+=" concept?

Charley Bay charleyb123 at gmail.com
Mon Apr 30 02:56:58 CEST 2012


>
> In addition to "bindings" and "assignment" (possibly including
> single-values or lists-of-values), is there a QML concept of "plus-equals"?
>
> For example:
>
> Item {
>   my_set0 : some_val0;      // replace value
>
>   // ...can I "accumulate" values?
>   my_set1  :+  added_val;   // Something like this?
>   my_set2  +:  added_val;   // Something like this?
> }
>
> Artem respondeth:

> Not in QML, but I you can implement it in JavaScript.
> You can implement an OnChanged: handler for a property and whenever it is
> changed add new value to some JavaScript list.
> Certainly you'll have to care about when you try adding the same value
> twice as that won't cause OnChange signal.
>

 The "OnNNN:" may be sufficient, but I was hoping for something more
elegant.

What I am curious about is why you need such an accumulative property. Why
> can't some addValue() javascript function suite you?
>

I *really* want to stay as "declarative/direct" as possible (not drop to
"imperative-Javascript" unless absolutely necessary, which seems quite
"indirect").  For example, the "OnNNN:" syntax seems a little "indirect"
and "unwieldy" when I merely want to "declare-an-accumulation".

The *concept* is interesting:  An item implicitly "grows" its list of
"children" (when the children "declare" their "parent").  I like that.  I
want more like that.  However, that works because the "one-to-many" is
*implied* (you can say, "That's-my-parent!", and the parent
"takes-ownership").  That won't work for "many-to-many" relationships, or
when you must specify the other-way-around (e.g,
"I-accept/take-that-item"), and that's a really common pattern/problem.

An example use would be the QML-description for the QBS build definition.
 I find the "describe-lists-of-files" quite awkward (e.g., "a-little-off").
 We *must* be able to declare *partial-sets* of things, with the
understanding that those sets will be *grown/adjusted* later.  It seems so
fundamental to me, and I see "go-to-Javascript" as the "goto-last-resort"
only when you have no other choice.

For this, "Make" and shells and pretty much all interpreted languages have
some kind of "+=", and it would-be-nice to have something "LISP-ish" like
"declare-these-as-appended-to-the-existing".

Fundamentally, "assignment/declared-binding" isn't enough, IMHO.  I could
even live with something like this:

Item {
  nested_set : [nested_set, another_item];
}

....but, that seems like a lot more work than:

Item {
  nested_set :+ another_item;
}

...when IMHO the following implies you *lost* all previous items, which
FREQUENTLY is not what you want:

Item {
  nested_set : another_item;  // oops!  lost previous items!
}

Just some thoughts.  (Cross-posting to the qbs-list, because there's very
little traffic there, and perhaps I misunderstand the solution to
partial-sets-of-files-that-later-get-resolved.)

--charley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20120429/d6f10ece/attachment.html>


More information about the Qbs mailing list