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. Difference between Qt's QML JS engine on Mac and Windows
Forum Update on Monday, May 27th 2025

Difference between Qt's QML JS engine on Mac and Windows

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 325 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
    Silex
    wrote on 2 Mar 2018, 23:43 last edited by Silex 3 Jun 2018, 12:48
    #1

    I have upgraded my project from Qt 5.6.2 to Qt 5.9.4 Had a couple of issues on mac when I tried to build for the first time with the new Qt version, but nothing major. I have merged these changes and switched to Windows in order to try to build my project there as well. Unfortunately with no success due to some JS issues.

    It looks like QML's JS engine works differently on Mac and Windows from Qt 5.9.4 (maybe earlier versions as well, didn't try) then it did on Qt 5.6.2.

    Here is a small example, which demonstrates the root cause of my issue:

        QtQuick.Item {
            QtQuick.Component.onCompleted: {
                function underscoreFind(obj, predicate, context) {
                    var findIndex = function(obj, predicate, context) {
                        for (var i = 0; i < obj.length; i++) {
                            if (predicate(obj[i])) {
                                return i;
                            }
                        }
                        return -1;
                    }
    
                    var key = findIndex(obj, predicate, context)
                    console.log("type of KEY " + (typeof key))
                    console.log("KEY IS " + key)
                    console.log("OBJ KEY IS " + obj[key])
                    var keycheck = (key !== void 0 && key !== -1)
                    if (key !== void 0 && key !== -1) {
                        console.log("#1 EVALUATING AS TRUE")
                    } else{
                        console.log("#1 EVALUATING AS  FALSE")
                    }
                    if (keycheck) {
                        console.log("#2 EVALUATING AS TRUE")
                    } else{
                        console.log("#2 EVALUATING AS  FALSE")
                    }
               }
               underscoreFind([,,5], function(obj){return obj !== undefined })
           }
        }
    

    Output on Mac:

    qml: type of KEY number
    qml: KEY IS 2
    qml: OBJ KEY IS 5
    qml: #1 EVALUATING AS  TRUE
    qml: #2 EVALUATING AS TRUE
    

    Output on Windows:

    qml: type of KEY number
    qml: KEY IS 2
    qml: OBJ KEY IS 5
    qml: #1 EVALUATING AS  FALSE
    qml: #2 EVALUATING AS TRUE
    

    Anybody hit this issue before? What is happening here exactly? How can I trust QML's JS Engine after this?

    The original problem have arisen in my original project within a library .js file. I am using underscore.js in my QML project as a .js library, which have worked just fine with Qt 5.6.2 and works just fine with Qt 5.9.4 on Mac, but fails at the _.find(...) function on Windows, which returns undefined always. As soon as I rename the function from _.find to something else like _.underscoreFind and change void 0 check to check it against undefined it works.

    This is the original implementation of _.find:

    _.find = _.detect = function(obj, predicate, context) {
          var key;
          if (isArrayLike(obj)) {
            key = _.findIndex(obj, predicate, context);
          } else {
            key = _.findKey(obj, predicate, context);
          }
          if (key !== void 0 && key !== -1) return obj[key];
      };
    

    and this is my modified function, which solves the issue on Windows:

    _.underscoreFind = function(obj, predicate, context) {
          var key;
          if (isArrayLike(obj)) {
            key = _.findIndex(obj, predicate, context);
          } else {
            key = _.findKey(obj, predicate, context);
          }
          if (key !== undefined && key !== -1) return obj[key];
      };
    

    Edit 1:

    This issue actually was introduced from Qt 5.6.3, aka 5.6.2 has the expected behavior, but 5.6.3 fails already on the above small test example.

    1 Reply Last reply
    0

    1/1

    2 Mar 2018, 23:43

    • Login

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