Javascript Containers Map, Set - supported?

  • Are Javascript containers like Map, Set and member functions like Set.has() supported by QML Javascript? I'm getting errors like this:

    qrc:/CheckTypes.js:9: ReferenceError: Set is not defined
    qrc:/CheckTypes.js:31: TypeError: Cannot call method 'has' of undefined

    "the QML runtime implements the ECMAScript Language Specification standard."

    // CheckShapes.js
    .pragma library
    var shapes = new Set(["Circle", "Triangle", "Square"]);
    function isShape(polygon) {
    	return shapes.has(polygon);
    // my.qml
    import QtQuick 2.9
    import "qrc:/CheckShapes.js" as Foo
    RowLayout {
      id: bar
      visible: (Foo.isShape(;  // Errors 
    RowLayout {
      id: bar2  // This one works.
      visible: ( === "Circle"   || 
       === "Triangle" || 
       === "Square");

    My understanding is that QML fully supports the inclusion of JavaScript files. I've written a lengthy .js file to be imported and used within .qml files. My Javascript's rusty but syntax is mostly copy+pasted from documentation.

    Am I missing a declaration at the top of my .js file to import standard JavaScript types? A compiler flag in my QTCreator Kit? Syntax error?

    Apple MacOS: 10.13.3
    QT Creator: 4.5.1 Based on 5.10.1 (Feb 10 2018, rev. 24cd0b1cd6)
    Project: QT 5.9.2

  • Unfortumately, the QML engine does not support ECMAScript 2015 aka ES6.

    The QML runtime implements the 5th edition of the standard

  • Unfortumately, the QML engine does not support ECMAScript 2015 aka ES6.

    Thank you @jpnurmi. Knowing JavaScript Frameworks exploded in popularity in the early 2000's I had no idea standard containers weren't added till 2015 nor that QML lagged that far behind the standard. Re-writing with arrays, my code fully doubled in size and went from near Constant Time to Linear. Disappointing. I guess that's just how it is.

  • Well, there is some it seems... just not all? I note there's quite a few comments: // ECMAScript 6 @:

    While I've not used it - that page has:
    map(callbackfn [, thisArg])
    but not Set.. not sure if that helps...

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.