我找不到一种从一个qml文件与另一个qml文件进行通信的方法。我知道有很多方法可以将信号从qml发送到C ++插槽并反向传输,但是我对两个不同qml文件之间的信号的所有研究都失败了。因此,如果有人可以告诉我如何解决这个问题,我将感到非常高兴。
首先是一个抽象的示例,以更好地理解问题。
基本的第一个QML看起来像这样:
//MyQML1.qml
Rectangle
{
id: idMyRec1
signal mySignalFromQML1()
Button
{
id: idMyButton1
onClicked:
{
idMyRec1.mySignalFromQML1(); //to send the signal
}
}
}
Run Code Online (Sandbox Code Playgroud)
第二个看起来像这样:
//MyQML2.qml
Rectangle
{
id: idMyRec2
Text{
id: idMyText2
text: "Hello World!"
onMySignalFromQML1: //to receive the signal from the other qml
{
idMyText2.text = "Good Bye World!";
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,此按钮应将我的第二个QML中的文本更改为“ Good Bye World!”。当单击时...但这不起作用...还有其他方法可以将信号从QML发送到另一个QML吗?还是我做错了什么?