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

mathias.malmqvist at nokia.com mathias.malmqvist at nokia.com
Sun Dec 19 16:19:03 CET 2010


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
 


More information about the Qt-qml mailing list