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

Creating default properties of list type in QML code is possible, but hackish.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: P2: Important P2: Important
    • None
    • 4.8.2
    • None
    • Win'7 MinGW

      Please take a look at the following code:

      //Host.qml
      import QtQuick 1.1
      
      Item {
          id: host
      
          //This gives two errors (hinting to "["):
          //"Expected token `numeric literal'"
          //"Expected a qualified name id"
          //
          //property list<Item> screens: []
      
          //This gives two errors (hinting to "<" and ">" respectively):
          //"Unexpected token `<'"
          //"Expected token `:'"
          //
          //default property list<Item> screens
      
          //This breaks too, with same errors as in above case
          //
          //default property list<Item> screens: []
      
          //This works
          property list<Item> screens
          default property alias screensProperty: host.screens
      }
      
      
      //test.qml
      import QtQuick 1.1
      
      Host {
          Item {
              objectName: "first"
          }
          Item {
              objectName: "second"
          }
      
          Component.onCompleted: {
              for (var i = 0; i < screens.length; i++)
                  console.log(screens[i].objectName)
          }
      }
      
      //outputs:
      //  first
      //  second
      

      Note, that declaring empty list properties (i.e. with an explicitly given "[]" value) does not work too. Should that be vied as a separate bug?

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

            Unassigned Unassigned
            mlvljr Vladimir M.
            Votes:
            9 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes