例如,在 文件1.qml
里定义了一个 TextInput
:
TextInput {
id: input1
...
}
然后有一个 文件2.qml
,如何在 文件2.qml
中获取 文件1.qml
中的 TextInput.text
?
同样的,如果有一个 文件3.cpp
,如何在 文件3.cpp
中获取 文件1.qmp
的 TextInput.text
呢?
先谢谢大家了!
例如,在 文件1.qml
里定义了一个 TextInput
:
TextInput {
id: input1
...
}
然后有一个 文件2.qml
,如何在 文件2.qml
中获取 文件1.qml
中的 TextInput.text
?
同样的,如果有一个 文件3.cpp
,如何在 文件3.cpp
中获取 文件1.qmp
的 TextInput.text
呢?
先谢谢大家了!
情况一的问题可以像下面这样解决:
QML1 名称定为 TextInputA.qml
TextInput {
id: input1
...
}
QML2 名称定为 TextInputB.qml
TextInput {
id: input2
...
}
现在你有一个使用这两个类的类,名称为ExampleA.qml
Item{
TextInputA{
id: inputA
}
TextInputB{
id: inputB
text: inputA.text
}
}
情况一的延伸,如果TextInputB被实例化在了一个叫做HelloC.qml的类中该怎么办?HelloC.qml的定义:
HelloC{
property alias text: inputB.text
TextInputB{
id: inputB
text: inputA.text
}
}
现在你有一个使用TextInputA和HelloC这两个类的类,名称为ExampleB.qml
Item{
TextInputA{
id: inputA
}
HelloC{
id: helloC
text: inputA.text
}
}
//////////////////////////////////////////////
对于情况二:
你可以在网上搜索 “QML和Qt交互” 来找答案了
希望这个回答可以帮到你和更多人,祝好!
7 回答5.3k 阅读
3 回答2k 阅读✓ 已解决
4 回答4.4k 阅读✓ 已解决
4 回答4k 阅读
2 回答3.9k 阅读✓ 已解决
2 回答5.9k 阅读✓ 已解决
2 回答3.2k 阅读✓ 已解决
qml使用的是统一的名称空间,只要包含,那么就可以引用其id,新手理解,勿喷~