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

QtQuick: Unset required property in Singleton is not an error?

    XMLWordPrintable

Details

    • Windows

    Description

      In my QML application I want to use exchangeable Singletons holding properties (as StyleSheets, so to speak).

      To have some kind of "virutal base class" defining all required properties, I've created a base QtObject holding all property declarations using required property. This way – I expected – any unset property was reported as an error.

      The attached example holds the "virtual base class" with two properties:

      SingletonBase.qml
      import QtQuick
      
      QtObject {
        required property int thisIsSet
        required property int thisIsNotSet
      }  

      The Singleton implements the base object and should set both, but intentionally only set one:

      Singleton.qml
      pragma Singleton
      import QtQuick
      
      SingletonBase {
        // Set the first "required" property:
        thisIsSet: 99
      
        // Do NOT set the second "required" property:
        // thisIsNotSet: 11
      } 

      When using the Singleton, the unset required property does not produce an error:

      Main.qml
      ...
          Text {
            text: "thisIsSet: " + Singleton.thisIsSet
          }
          Text {
            text: "thisIsNotSet: " + Singleton.thisIsNotSet
          }
      ...
      

      Its value is "0":

      thisIsSet: 99
      thisIsNotSet: 0
      

      Other types also use some default (i.e. color = "black").

       

      Expected Result:

      "thisIsNotSet" is reported similarly to:

      QQmlApplicationEngine failed to create component
      "Required property thisIsNotSet was not initialized"

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-122784
          # Subject Branch Project Status CR V

          Activity

            People

              fabiankosmale Fabian Kosmale
              s.delker Stefan Delker
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change