[Qt-qml] Storing javascript references in QML properties, in Qt5

Pelle Johnsen pelle.johnsen at gmail.com
Tue Jun 7 09:45:35 CEST 2011


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 <vivainio at gmail.com> 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 <vivainio at gmail.com>
> 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
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110607/3cc4a4f5/attachment.html 


More information about the Qt-qml mailing list