[Qt-qml] Cannot store javascript object in property, why?

jyrki.yli-nokari at nokia.com jyrki.yli-nokari at nokia.com
Tue Dec 21 14:32:44 CET 2010


Personally I vote for a simple low-overhead solution that enables one to
mark the desired objects (and arrays) bindable. It does not have to be
automatic but it must be possible and low overhead. Now using a ListModel
to mirror/emulate array is not exactly the best possible use of the CPU
time.

On 21.12.2010 1.47, "ext michael.brasser at nokia.com"
<michael.brasser at nokia.com> wrote:

>On 17/12/2010, at 11:54 PM, ext Ville M. Vainio wrote:
>
>> Currently, you cannot store javascript objects as properties in qml
>> components, e.g. you can't do
>> 
>> propery JSRef myobj
>> 
>> function setCallback(f) { myobj = f };
>> 
>> On irc #qt-qml, this explanation was quoted:
>> 
>> QQQ
>> In QML "property var" cannot store JavaScript native objects, as we
>> cannot bind to them. This might change in a future release. For now,
>> more explicit warnings are generated when you accidentally do this.
>> QQQ
>
>The core problem is that properties on a JS object don't give any
>notification when they are changed (in contrast to a QObject, which uses
>NOTIFY signals to inform when a property has changed). This means if you
>bind to such a property, e.g.
>
>Text { text: myobj.textProp }
>
>the binding will *not* be updated if you do something like
>
>function myFunction() { myobj.textProp = "New Text" }
>
>This is the reason we don't currently support it -- we didn't want to
>make it possible for these bindings to "silently fail" (and from memory
>providing a warning for such bindings was also non-trivial).
>
>> I can't claim to understand the explanation, but I'm curious whether
>> we will have this feature in the near future - as the lack of it seems
>> to be a pretty fundamental shortcoming in QML, and workarounds (like
>> storing the reference in a .js file, or using C++) seem quite hacky in
>> comparison.
>
>
>We certainly want to make JS/QML integration more seamless, but I'm not
>sure exactly how or when this will happen. It's not currently planned as
>part of the next release (QtQuick 1.1).
>
>Regards,
>Michael
>_______________________________________________
>Qt-qml mailing list
>Qt-qml at qt.nokia.com
>http://lists.qt.nokia.com/mailman/listinfo/qt-qml



More information about the Qt-qml mailing list