Tôi là một lập trình viên qml mới và tôi thấy bản thân mình trong vấn đề này khi tôi muốn gọi một trang mới khi nhấp vào một nút, nó nói:
TypeError: Cannot call method 'push' of null
Tôi đã thử tất cả mọi thứ tôi biết để giải quyết điều này nhưng vẫn không có gì.
Đây là mã của tôi:
import QtQuick 2.0
import Ubuntu.Components 0.1
import "components"
MainView {
objectName: "mainView"
applicationName: "com.ubuntu.developer..EcoLover3"
automaticOrientation: true
width: units.gu(48)
height: units.gu(60)
PageStack {
id: pagestack
Component.onCompleted: push(page0)
Page {
id: page0
title: i18n.tr("Bem Vindo à aplicação do EcoLover" )
visible: false
Text {
id: entrada
text: qsTr("Caro Cliente, <br>aqui poderá contrloar os seus gastos de energia</br>")
}
Column {
anchors.margins: units.gu(3)
spacing: units.gu(3)
anchors.fill: parent
Image{
anchors.horizontalCenter: parent.horizontalCenter
source: "/home/diogo/ecoLover_teste2/components/Ecolover_com_stroke.png"
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: i18n.tr("Page one")
onClicked: pageStack.push(page1, {color: UbuntuColors.orange})
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: i18n.tr("Entrar no EcoLover")
onClicked: pageStack.push(Qt.resolvedUrl("Pagina_inicial.qml"))
}
}
}
Page {
title: "Rectangle"
id: page1
visible: false
property alias color: rectangle.color
Rectangle {
id: rectangle
anchors {
fill: parent
margins: units.gu(5)
}
}
}}}