Details
-
Task
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.4.2, 6.5.0 Beta1
-
None
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!