Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-57639

QML ListModel converts null into 0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.6.2, 5.7.0, 5.7.1
    • None
    • Debian 8 amd64
      Qt from online installer

    Description

      If I have list like this:

      var list = [0, null, 1];
      

      And add values into ListModel:

      append({ value : list[0]});
      append({ value : list[1]});
      append({ value : list[2]});
      

      get(1).value returns 0, not null.

      Whole test app:

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.1
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
      
          Pane {
      
              ListModel {
                  id: listModel
                  Component.onCompleted: {
      
                      var list = [0, null, 1];
      
                      console.log(list[0]);
                      console.log(list[1]); // outputs null
                      console.log(list[2]);
      
                      console.log("---");
      
                      append({ value : list[0]});
                      append({ value : list[1]});
                      append({ value : list[2]});
      
                      console.log(get(0).value);
                      console.log(get(1).value); // outputs 0, not null !!!
                      console.log(get(2).value);
                  }
              }
      
              Column {
                  Repeater {
                      model: listModel
      
                      Text {
                          text: model.value === null ? "?" : model.value // question mark is not displayed
                      }
                  }
              }
          }
      }
      
      

      Console output:

      qml: 0
      qml: null
      qml: 1
      qml: ---
      qml: 0
      qml: 0
      qml: 1
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            wearyinside Oleg Yadrov
            talkless Vincas Dargis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes