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

Null properties get converted to QVariant(void*) when put inside a QML model

    XMLWordPrintable

Details

    Description

      I have a list of objects with properties, constructed by parsing a JSON string. Some of these properties are null. This list of object is then used as the model of a ListView component.

      The problem is, any 'null' property is converted to a QVariant(void*) inside the list model, and there doesn't seem to be any way of knowing that this QVariant(void*) is a null value.

      ListView
      {
          Component.onCompleted:
          {
              var result = [{'test': null}];
              print("original value:", result[0].test);
              model = result;
              print("in model:", model[0].test);
          }
      
          delegate: Item
          {
              Component.onCompleted:
              {
                  var t = modelData.test;
                  print("in delegate:", t);
                  print(t === null, t === undefined, t === false, t === "");
              }
          }
      }
      
      qml: original value: null
      qml: in delegate: QVariant(void*)
      qml: false false false false
      qml: in model: QVariant(void*)
      

      The real context: the JSON string is returned by a web service, and the null values are supposed to be strings. These strings are assigned to Text components. And because of this problem, I have no way of handling null strings correctly (without QML errors).

      Attachments

        Issue Links

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

          Activity

            People

              laknoll Lars Knoll
              laurentgom Laurent
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes