7
访问QML项目,我开始学习QML,我发现了以下错误:不能由ID内SPLITVIEW
ReferenceError: chatTextArea is not defined
我有一个全局函数,它在同一个QML内的项目的东西文件,由id。
出于某种原因,我无法通过我的TextArea的ID或SplitView中的任何项目进行访问。但是我能够操纵TabView和每个Tab的属性。
我断码:
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
Rectangle {
id: lobby
function appendChatMsg(msg) {
chatTextArea.append(msg) //causes: ReferenceError: chatTextArea is not defined
}
TabView {
id: frame
Tab { //I CAN access this item via ID.
id: controlPage
SplitView {
anchors.fill: parent
TableView {
Layout.fillWidth: true
}
GridLayout {
columns: 1
TextArea { //This item I CANNOT access via ID.
id: chatTextArea
Layout.fillHeight: true
Layout.fillWidth: true
}
TextField {
placeholderText: "Type something..."
Layout.fillWidth: true
}
}
}
}
}
}
任何想法,为什么chatTextArea超出了我的函数的范围是什么?提前致谢。
谢谢!这消除了错误。 但是我仍然有困难。我正在尝试回复“主”QML文件中的信号。我的大厅通过Loader动态加载到main.qml中。当main.qml中的信号被触发时,如何在Lobby.qml中触发我的函数? – jub 2014-09-05 03:09:38
你可以在范围链中通过id访问main,并通过'signalName.connect()'连接到它的信号,我想(可能在大厅的'onCompleted()')。 – mlvljr 2014-09-05 11:40:40