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

Initial readonly property is not set when using Loader.setSource

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.15.1
    • None

    Description

      According to the docs

      > Read-only properties must be assigned a value on initialization. 

      When I use a loader like this:

      import QtQuick 2.12
      import QtQuick.Window 2.12
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Component.onCompleted: loader.setSource("qrc:/RectTest.qml", {  "text": "asasas"})
          Loader {
              id: loader
              anchors.fill: parent
          }
      }
      
      //RectTest.qml
      import QtQuick 2.0
      
      Rectangle {
          id:root
          color: "orange"
          readonly property string text: ""
      
          Text {
              text:root.text
              color: "white"
              anchors.centerIn: parent
          }
      
      }
      

      I would assume that this sets the initial value of the component, like a c++ constructor. Also there is no error message when creating a component like this and trying to set a readonly member.

       

      See attached example

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            kelteseth Elias Steurer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes