Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Javascript Containers Map, Set - supported?
QtWS25 Last Chance

Javascript Containers Map, Set - supported?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
javascriptqmljavascript qmlcontainershash
4 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StevenFS
    wrote on 22 Feb 2018, 20:58 last edited by
    #1

    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."
    http://doc.qt.io/qt-5/qtqml-javascript-hostenvironment.html

    // 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(myPolygon.name));  // Errors 
    };
    
    RowLayout {
      id: bar2  // This one works.
      visible: (myPolygon.name === "Circle"   || 
                myPolygon.name === "Triangle" || 
                myPolygon.name === "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 Mozilla.org 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?

    --
    Environment:
    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

    C++ Software Engineer

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jpnurmi
      wrote on 22 Feb 2018, 22:44 last edited by jpnurmi
      #2

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

      The QML runtime implements the 5th edition of the standard

      https://bugreports.qt.io/browse/QTBUG-47735

      S 1 Reply Last reply 23 Feb 2018, 17:39
      3
      • J jpnurmi
        22 Feb 2018, 22:44

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

        The QML runtime implements the 5th edition of the standard

        https://bugreports.qt.io/browse/QTBUG-47735

        S Offline
        S Offline
        StevenFS
        wrote on 23 Feb 2018, 17:39 last edited by StevenFS
        #3

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

        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.

        C++ Software Engineer

        1 Reply Last reply
        0
        • 6 Offline
          6 Offline
          6thC
          wrote on 26 Feb 2018, 01:20 last edited by
          #4

          Well, there is some it seems... just not all? I note there's quite a few comments: // ECMAScript 6 @: http://doc.qt.io/qt-5/qtqml-javascript-functionlist.html

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

          1 Reply Last reply
          0

          1/4

          22 Feb 2018, 20:58

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved