Qt快速控件TabView中的ReferenceError [英] ReferenceError in qt quick controls tabview
本文介绍了Qt快速控件TabView中的ReferenceError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用TabView编写了QT Quick程序.当我单击Tabview中的botton b1时,程序应调用show_text()并打印b1的文本,但它会显示"ReferenceError:未定义b1".任何建议将不胜感激,谢谢.
I have written a QT Quick program use TabView. When I click the botton b1 which is in Tabview, the program should call show_text() and print the text of b1, but it print "ReferenceError: b1 is not defined". Any suggestion will be appreciated, thanks.
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.1
ApplicationWindow {
function show_text() {
console.log(b1.text)
}
TabView {
id: tv
Tab {
id: tab1
Button{
id: b1
text:"b1's text"
onClicked: {
//console.log(b1.text)
show_text()
}
}
}
}
}
推荐答案
将对象作为参数传递
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.1
ApplicationWindow {
function show_text(myobject) {
console.log(myobject.text)
}
TabView {
id: tv
Tab {
id: tab1
Button{
id: b1
text: "b1's text"
onClicked: {
show_text(b1)
}
}
}
}
}
这篇关于Qt快速控件TabView中的ReferenceError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文