gpt4 book ai didi

javascript - 如何获取QML中项目的基类?

转载 作者:行者123 更新时间:2023-12-03 12:24:26 24 4
gpt4 key购买 nike

有没有办法在QML中获取项目类?我知道 objectNameid 等,但看起来有点奇怪,不太舒服。这就是我需要的:

ComboBox {
id: comboBox
}
TextField {
id: textField
}

function getValue(item) {
switch(item.???) { //what property can I use here?
case 'ComboBox':
return item.model.get(item.currentIndex).value;
case 'TextField':
return item.text;
}
}

按照互联网上许多文章所述使用 objectName 可能会含糊不清且过度,例如:

ComboBox {
id: comboBox
objectName: "ComboBox"
}
TextField {
id: textField
objectName: "ComboBox" /// oops!!
}

function getValue(item) {
switch(item.objectName) {
case 'ComboBox':
return item.model.get(item.currentIndex).value;
case 'TextField':
return item.text;
}
}

最佳答案

不,这只能通过 C++ 完成。

关于javascript - 如何获取QML中项目的基类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24274685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com