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

QML: Treat "required property" as FINAL

    XMLWordPrintable

Details

    Description

      Code

      import QtQuick
      
      Window {
          id: window
          width: 640
          height: 480
          visible: true
      
          component Config: QtObject { required property color winColor }
          component BadConfig: Config { property color winColor: "beige" }
      
          property Config cfg: BadConfig { winColor: "yellow" }
          color: window.cfg.winColor
      }
      

       

      Outcomes
      At compile time, qmlsc says,

      Warning: Main.qml:13:20: Member winColor of QObject of (component in Main.qml)::cfg with type Config can be shadowed [compiler]
      	color: window.cfg.winColor
                        	^^^^^^^^
      

       

      And indeed, BadConfig is trying to shadow it. However, it cannot do that because we get this at runtime:

      QQmlApplicationEngine failed to create component
      qrc:/qt/qml/untitled4/Main.qml:9:31: Required property winColor was not initialized
      

       

      Suggestion

      Since it is impossible to shadow a required property without blocking the object's initialization, could we treat that property as FINAL?

      • (Primary suggestion) qmlsc shouldn't warn that Config.winColor can be shadowed
      • (Secondary suggestion) BadConfig trying to implement a new property called winColor should be treated as an error

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              skoh-qt Sze Howe Koh
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes