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

Empty property initializer produces unexpected result

XMLWordPrintable

    • 89cdaa901d227bed35f6c5405ce5d62f352a659c

      When a variant property is declared with an empty object initializer, it produces an unexpected 'undefined' state, because the javascript engine does not know whether to interpret the empty declaration as an empty object or an empty function.

      import QtQuick 2.0
      
      Item {
          property variant v1: {}
          property variant v2: ({})
      
          Component.onCompleted: {
              console.log("v1:", v1);   // 'undefined'
              console.log("v2:", v2);
      
              v1 = {};
              console.log("v1:", v1);
          }
      }
      

      The problem is easily avoided by the non-obvious solution of wrapping the declaration in parentheses.

      Is it possible (or desirable) for QML to force the declaration to be intepreted as an object? Otherwise, should the compilation fail?

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

            chriadam Christopher Adams (closed Nokia identity) (Inactive)
            mvogt Matthew Vogt (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes