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

Document default values for properties defined in QML

    XMLWordPrintable

Details

    • 8217da65cbe44261a83418017be311bb1a62725d

    Description

      The section "Extending types from QML" (http://qt.nokia.com/doc/4.7-snapshot/qml-extending-types.html) should be extended to document the "default" default value per type .

      Qml seems to have decent default values for some of the built-in types. E.g. if you have a dynamic property declared as "property bool b", and do not assign it an explicit value, b will be 'false'. I tried to find out about the default values used by this JavaScript snippet:

      import Qt 4.6
      
      Rectangle {
        width: 200
        height: 200
      
        property int i
        property bool b
        property double d
        property real r
        property string s
        property url u
        property color c
        property date dt
        property var v
      
      
        MouseArea {
          anchors.fill:parent
          onClicked: {
            print("Values\n");
            print("int: " + i);
            print("bool: " + b);
            print("double: " + d);
            print("real: " + r);
            print("string: "+ s);
            print("url: " + u);
            print("color: " + c);
            print("date: " + dt);
            print("var: " + v);
          }
        }
      }
      

      which prints

      Values
      
      int: 0
      bool: 0
      double: 0
      real: 0
      string:
      url:
      color: #000000
      date: Invalid Date
      var: undefined
      

      This means also that you can bind to all variables above, except for date and var, which result in runtime warnings:

      [...] Unable to assign QDateTime to QDate
      [...] Unable to assign [undefined] to QVariant
      

      Can this be maybe added to the documentation?

      Attachments

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

        Activity

          People

            aalpert-nokia Alan Alpert (closed Nokia identity) (Inactive)
            kkohne Kai Köhne
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes