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

A description about Loader is not clear enough

    XMLWordPrintable

Details

    Description

      In this document(https://doc.qt.io/qt-6/qml-qtquick-loader.html#receiving-signals-from-loaded-objects), there's a sentence :

       

       it could also directly call any function defined in the Loader or its parent Item. 

      But the part "or its parent Item" is not clear.

       

      I did a little experiment like this:

      // Main.qml
      import QtQuick
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")    
          Item {
              id: itm
              width: 200; height: 200
              function helloItem() {
                  console.log("hello from Item")
              }       
              Loader {
                  x: 50
                  function hello() {
                      console.log("hello from Loader")
                  }
                  source: "Loded.qml"
              }
          }
      } 
      import QtQuick
      Rectangle {     
          width: 100
          height: 100     
          color: "red"     
          x: 150     
          Component.onCompleted: {         
             hello()         
             helloItem()     
          } 
      }
      

      The point of this experiment is that Loader has a parent "Item" with a function helloItem().
      But calling it yields this error:

       

      // output
      qml: hello from Loader
      qrc:/loaderAnchorTest/Loded.qml:10: ReferenceError: helloItem is not defined 

      Which seems to be contradicting "or its parent Item."

      The issue here seems that the definition of "its parent Item" is not clear enough.
      I think the documentation should be fixed in a way that it'll make it clear.

       

      Attachments

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

        Activity

          People

            docteam Qt Documentation Team
            mikio_hirai Mikio Hirai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes