[Qt-qml] How to add/remove/count items in a list<Item> property from within javascript?

aaron.kennedy at nokia.com aaron.kennedy at nokia.com
Tue Oct 26 16:12:32 CEST 2010


Hi,

By default, yes.  If you want the js file to be shared, include the line ".pragma library" at the top.

Cheers,

Aaron

On 27/10/2010, at 12:05 AM, "ext Bart Kelsey" <elbarto at gmail.com<mailto:elbarto at gmail.com>> wrote:

Thanks for the reply!

Another question, then: If I have several instances of the same component, do they each have their own copy of the global variables declared in the external javascript file?

Bart


On Mon, Oct 25, 2010 at 9:05 PM, <<mailto:michael.brasser at nokia.com>michael.brasser at nokia.com<mailto:michael.brasser at nokia.com>> wrote:
On 26/10/2010, at 6:04 AM, ext Bart Kelsey wrote:

> Greets!
>
> I'm trying to create a list of Items, and it's not clear to me, from within JavaScript, how to add, remove, and count those items.  The function below doesn't seem to work (textArray is declared as "property list<Item> textArray").  Note that my startUp function is being correctly called, and I can verify that the TalkBoxTextComponent.createObject method is working.  I've tried using .push(), .append(), length, etc, and I'm having no luck so far.
>
> ******
>
> var TalkBoxTextComponent;
>
> function startUp() {
>   TalkBoxTextComponent = Qt.createComponent("TalkBoxText.qml");
> }
>
> function appendText(string) {
>   var object = TalkBoxTextComponent.createObject(talkbox);
>   object.text = string;
>   talkbox.textArray[0] = object;
>   talkbox.textArray[1] = object;
> }

Manipulating QML list properties from javascript is not well documented at the moment (<http://bugreports.qt.nokia.com/browse/QTBUG-14645>http://bugreports.qt.nokia.com/browse/QTBUG-14645), and as they behave differently from javascript Arrays, it can sometimes get a bit confusing.

The best way I know how to explain the current list property support is to say that writing to a list _property_ is supported, but writing to the list itself is not. To give examples:

(1) textArray = [object, object]    //supported, writes a new array of two items to the property textArray
(2) textArray = []    //supported, writes an empty array to the property textArray (i.e. clears the textArray property)

(3) textArray[1] = object    //not supported, tries to modify the list itself
(4) textArray.push(object)    //not supported, tries to modify the list itself

There are challenges with supporting (3) and (4) and having bindings involving textArray update correctly, which is why they are not yet supported. It's a limitation we don't like, and want to fix in a future release (probably by having lists support some form change notifications, much like list models do). The workaround for now, if you need a writable list, is to use a javascript Array (the samegame demo shows an example of this).

Regards,
Michael



--
--

_______________________________________________
Qt-qml mailing list
Qt-qml at trolltech.com<mailto:Qt-qml at trolltech.com>
http://lists.trolltech.com/mailman/listinfo/qt-qml
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101026/f87aa75e/attachment.html 


More information about the Qt-qml mailing list