[Qt-qml] How to get list of map's keys?

mathias.malmqvist at nokia.com mathias.malmqvist at nokia.com
Sun Dec 19 19:06:29 CET 2010


AWESOME!

Thanks! :)




Cheers
Mathias

________________________________________
From: Overdick Hagen (Nokia-MS/Berlin)
Sent: Sunday, December 19, 2010 5:03 PM
To: qt-qml at qt.nokia.com; Malmqvist Mathias (Nokia-MS/London)
Subject: Re: [Qt-qml] How to get list of map's keys?

Actually, Javascript has just gained a new syntax which QML is already
supporting:

Object.keys(theMap)

will return the desired array.

Regards,
Hagen

On 12/19/10 5:41 PM, "ext petrus.lundqvist at nokia.com"
<petrus.lundqvist at nokia.com> wrote:

>You have described a JavaScript object using JSON notation - not a QML
>map as you call it. In JS you iterate keys in objects (which do double
>duty as maps) using for-in loops.
>
>The documentation you seek can be found in JavaScript books or tutorials
>- not Qt ones.
>
>Peppe
>
>-----Original Message-----
>From: Malmqvist Mathias (Nokia-MS/London)
>Sent:  19.12.2010, 17:19
>To: qt-qml at qt.nokia.com
>Subject: [Qt-qml] How to get list of map's keys?
>
>Hi everyone,
>
>How can I get a list of the keys in a QML map?
>
>Defining a map like this works:
>property variant theMap: { "key1":"value1", "key2":"value2",
>"key3":"value3" }
>
>Now I want to know all the keys used in the map, i.e. something like this
>function keys() {
>    var theKeys = theMap.keys();
>    return theKeys;
>}
>
>that I would expect to return an array like this:
>["key1", "key2", "key3"]
>but it seems the map object doesn't have a keys() function, or anything
>else similar I've tried.
>Is that so, or have I just not found the right syntax?
>
>The map type is missing from the documentation of basic QML types:
>http://doc.qt.nokia.com/4.7-snapshot/qdeclarativebasictypes.html
>(see http://bugreports.qt.nokia.com/browse/QTBUG-16196)
>
>
>Cheers
>Mathias
>
>_______________________________________________
>Qt-qml mailing list
>Qt-qml at qt.nokia.com
>http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>_______________________________________________
>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