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

Parent and anchor issues with loaded components

    XMLWordPrintable

Details

    • 0b175f5f224e33f4e51873607fe78a4c203ab896

    Description

      Running the code below should result in a 100x100 pixels blue rectangle
      in the center of a white window. Instead the entire window is blue.
      Also, the "parent" property of the blue rectangle is not set by the time its
      Component.onCompleted is called.

      import Qt 4.7
      
      Rectangle {
          width:  800
          height: 460
      
          Loader {
              objectName: "the loader"
              anchors.fill: parent
              sourceComponent: blueRect
          }
      
          Component {
              id: blueRect
              Rectangle {
                  objectName: "blue rectangle"
                  width: 100; height:  100    // Bug: Rect fills the loader
                  anchors.centerIn: parent
                  color: "blue"
                  Component.onCompleted: print("Parent: " + parent.objectName)   // Bug: "parent" is null
                  Timer {
                      running: true
                      interval: 1000
      //                onTriggered: { print(parent); }                 // Bug: Results in "null" printed
      //                onTriggered: { print("Parent: " + parent); }  // Works fine
                      onTriggered: { print("Parent of blue rect: " + parent.parent.objectName); } // Now blue rect has a parent
                  }
              }
          }
      }
      

      Attachments

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

        Activity

          People

            martjone Martin Jones (closed Nokia identity) (Inactive)
            mathiasm Mathias Malmqvist
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes