Qt QML引用错误
我有一个小的QML项目,我面临着QML组件引用的问题。所以我试图从main.qml中的startButton启动NumComponent.qml的numberTimer main.qmlQt QML引用错误,qt,reference,qml,qt-creator,Qt,Reference,Qml,Qt Creator,我有一个小的QML项目,我面临着QML组件引用的问题。所以我试图从main.qml中的startButton启动NumComponent.qml的numberTimer main.qml import QtQuick 2.7 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") NumComponent{} /
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
NumComponent{} //my component written in NumComponent.qml
Rectangle{
id: startButton
anchors.centerIn: parent
height: parent.height * 0.2
width: height
color: "lightblue"
MouseArea{
anchors.fill: parent
onClicked: {
numberTimer.start();
}
}
}
}
import QtQuick 2.0
Rectangle {
id: numberRect
color: "red"
height: parent.height * 0.4
width: height
Text{
id: numberText
anchors.centerIn: parent
text: ""
}
Timer{
id: numberTimer
interval: 100
repeat: true
onTriggered: {
numberText.text = Math.floor(Math.random() * 8);
}
}
}
NumComponent.qml
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
NumComponent{} //my component written in NumComponent.qml
Rectangle{
id: startButton
anchors.centerIn: parent
height: parent.height * 0.2
width: height
color: "lightblue"
MouseArea{
anchors.fill: parent
onClicked: {
numberTimer.start();
}
}
}
}
import QtQuick 2.0
Rectangle {
id: numberRect
color: "red"
height: parent.height * 0.4
width: height
Text{
id: numberText
anchors.centerIn: parent
text: ""
}
Timer{
id: numberTimer
interval: 100
repeat: true
onTriggered: {
numberText.text = Math.floor(Math.random() * 8);
}
}
}
我得到这个错误:“qrc:/main.qml:22:ReferenceError:NumberError未定义”
NumComponent{
id: numComponent
} //my component written in NumComponent.qml
property alias timed: numberTimer.running
NumComponent{
id: numComponent
} //my component written in NumComponent.qml
property alias timed: numberTimer.running
现在您可以启动和停止计时器。这是因为NumComponent是一个封闭的对象。您可以将numberRect(或您的numberTimer)用作或公开为,这是因为NumComponent是一个封闭的对象。您可以使用或公开numberRect(或您的numberTimer)作为