Important: Please read the Qt Code of Conduct -

[SOLVED]Strange JS behavior

  • 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: !!
    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

  • 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.

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

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

Log in to reply