Files
qt6-qml-for-beginners/Qt6QMLBeginnersCode/4.SignalsSlots/8-ConnectingSignalsToSignals/Main.qml
2025-09-28 17:05:51 +08:00

46 lines
1.1 KiB
QML

// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("Custom Signals")
Rectangle{
id: rectId
width: 300
height: 300
color: "dodgerblue"
anchors.left: parent.left
//Set up the signal
signal greet(string message)
signal forward_greeting(string message)
//We want to connect, not to a build in signal handler, but to a custom
//regular function
function respond_your_way(message){
console.log("Responding our way;Greeting with message: "+message)
}
MouseArea{
anchors.fill: parent
onClicked: {
//Fire the signal by just calling it like a function
rectId.greet("The sky is blue")
}
}
Component.onCompleted: {
//Connect a signal to another signal
rectId.greet.connect(rectId.forward_greeting)
//Respond to the final signal
rectId.forward_greeting.connect(rectId.respond_your_way)
}
}
}