Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [SOLVED]Strange JS behavior

    QML and Qt Quick
    2
    4
    1650
    Loading More Posts
    • 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.
    • I
      ixSci last edited by

      Hi there!

      I've just stumbled on some strange JavaScript behavior which I don't understand totally.
      I have the following code for one of the QML item property:
      @xMax: {
      var maximum = 0;

                 for(var i = 0; i < xMarks.length; i++){
                     var data = xMarks[i];
                     console.log("data: " + data + ", maximum:" + maximum + ", result: " + (data > maximum))
                     if(data > maximum){
                         maximum = data;
                     }
                  }
                  return maximum;
            }@
      

      And it prints: !http://ybex.com/t/in8iai32h6khg3r2u72ph5x5kbb4homykr9ue41s.png(that)!
      It works as such with all values more then 6. It works as it should with all values less then 6. Is it a bug? It seems very strange to me

      1 Reply Last reply Reply Quote 0
      • P
        pvarga last edited by

        Hi ixSci,

        I have tried your example and it works for me.
        What is the type of the xMarks array? I created an own one for the test:
        @
        var xMarks = new Array(6.0, 12.0, 18.0, 30.0);
        @
        With this array the console.log prints it in integer format instead of double (e.g. "6" instead of "6.00").
        Could you share more information about the using of xMax property? I just started to get acquainted with QML.

        1 Reply Last reply Reply Quote 0
        • I
          ixSci last edited by

          Hi pvarga, xMarks has QList<float> type and it is provided by the C++ side

          1 Reply Last reply Reply Quote 0
          • I
            ixSci last edited by

            So, bug not in the JS but in my code instead. xMarks is not QList<float> but QList<QString>.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post