Trying to store javascript arrays or objects in QML properties has some
bizarre behavior in 4.7.2. I suspect they get converted to QVariant. See
this simple example:
import QtQuick 1.0
Rectangle {
id: rect
width: 400
height: 400
property variant afoo: [1,2,3,4]
property variant ofoo: {'name': 'jane', 'id': 1, 'ref': rect}
Component.onCompleted: {
afoo[0] = 17;
console.log("afoo[0]: " + afoo[0]);
ofoo.id = 42;
console.log("ofoo.id: " + ofoo.id);
console.log("afoo: " + typeof(afoo));
console.log("ofoo: " + typeof(ofoo));
}
}
which outputs:
afoo[0]: 1
ofoo.id: 1
afoo: object
ofoo: object
So the js array and object stored in the variant property becomes read-only.
This is very confusing :S
-Pelle
On Tue, Jun 7, 2011 at 9:32 AM, Ville M. Vainio <[email protected]> wrote:
> Re-sending to qt-qml mailing list (perhaps it should be used instead
> of Qt5 feedback for QML language discussion?
>
> On Sun, Jun 5, 2011 at 2:25 PM, Ville M. Vainio <[email protected]>
> wrote:
> > Currently, it's not possible to store references to javascript objects
> > (Array, Object, functions...) in QML properties (yes, "propery
> > variant" can't hold a js reference). I believe the rationale for this
> > is that you can't use javascript references in property bindings.
> >
> > Will there be a fix for this in Qt Quick 2?
> >
> _______________________________________________
> Qt-qml mailing list
> [email protected]
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml