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

QML signals do not work when fired from Component.onCompleted with an outside Connection

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.4.2, 6.5.0 Beta1
    • None
    • All

    Description

       

      QML signals do not work when fired from Component.onCompleted with an outside Connection. I can see how this is expected behavior for an experienced Qt dev (when signals are connected under the hood), but this just took me way to long to figure out. This should be fixed or written down in the docs. I tested this also with 6.6.0.

      import QtQuickWindow {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")    
          Component.onCompleted: {
              loader.source = "qrc:/QmlMissingSignal/MyQmlElement.qml"
          }    
          Connections {
              id: loaderConnections        
             function onMessage(msg) {
                  console.log("msg from loader.item: ", msg)
              }        
              target: loader.item
          }
          Loader {
              id: loader
              anchors.fill: parent
          }
      }
       

      MyQmlElement.qml

       

       

      import QtQuickRectangle {
          id: root
          color: "Orange"
          signal message(string msg)
          Timer {
              interval: 100
              running:true
              onTriggered: {
                  print("Fire from Timer.")
                  root.message("Message from Timer!")
              }
          }    
          Text {
              color: "white"
              text: "MyQmlElement.qml loaded"
              anchors.centerIn: parent
          }    
          Component.onCompleted: {
              print("Fire from onCompleted")
              root.message("Message from  onCompleted")
          }
      }
       

      Expected:

       

       

      qml: Fire from onCompleted
      qml: msg from loader.item:  Message from  onCompleted
      qml: Fire from Timer.
      qml: msg from loader.item:  Message from Timer! 

      Actual output:

       

       

      qml: Fire from onCompleted
      qml: Fire from Timer.
      qml: msg from loader.item:  Message from Timer! 

      QmlMissingSignal.zip

       

      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:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes