QML不改变状态

QML不改变状态,qml,qt4,Qml,Qt4,我正在创建一个应用程序,但qml中的状态没有更改…此处LoginView是一个qml文件,MessageView也是一个qml文件我想将qml文件更改为应用程序的页面…我做错了什么,但我无法找出原因…请帮助我 import QtQuick 1.0 Item { id: main LoginView { id: login anchors.fill: parent visible: true onLoginClicked: main.state="message

我正在创建一个应用程序,但qml中的状态没有更改…此处
LoginView
是一个qml文件,
MessageView
也是一个qml文件我想将qml文件更改为应用程序的页面…我做错了什么,但我无法找出原因…请帮助我

import QtQuick 1.0

Item {
id: main

LoginView {
    id: login
    anchors.fill: parent
    visible: true
    onLoginClicked: main.state="messageView"
}

MessageView {
    id: message
    anchors.fill: parent
    visible: false
}

states: [State {
        name:"messsageView"
        PropertyChanges { target: login; visible: false }
        PropertyChanges { target: message; visible: true }
    },State {
        name:""
        PropertyChanges { target: message; visible: false }
        PropertyChanges { target: login; visible: true }
    }]
}

当某些“事件”发生时,不应该发生变化吗。大概是这样的:

import QtQuick 1.0

Rectangle
{

    id: main
    color: "blue"
    width : 200
    height: 200

Rectangle
{
    id: login
    color: "red"
    anchors.fill: parent
    opacity: 1
}

Rectangle {
    id: message
    color: "green"
    anchors.fill: parent
    opacity: 0
}

// --------------------------- THIS! ---------------------

MouseArea
{
 anchors.fill: parent
 onClicked: parent.state = "messsageView"
}

// -------------------------------------------------------

states: [State {
        name:"messsageView"
        PropertyChanges { target: login; opacity: 0 }
        PropertyChanges { target: message; opacity: 1 }
    },State {
        name:""
        PropertyChanges { target: message; opacity: 0 }
        PropertyChanges { target: login; opacity: 1 }
    }]

}
你做的​​打字错误。 看看这段代码:

LoginView {
id: login
anchors.fill: parent
visible: true
onLoginClicked: main.state="messageView" //state name is "messageView"
}
其次是:

states: [State {
    name:"messsageView" // TRIPLE "s"
    PropertyChanges { target: login; opacity: 0 }

但是在两个QML中都有
按钮
元素,它们生成一些事件。我只想将该事件连接到此主QML。为什么使用不透明而不是可见?为什么要为默认状态编写无用的属性更改?@Matteo这是在'13年回答的,如果我没记错的话,当时Qt中没有可见的标志。这不是真的,
visible
存在于2013年推出的qt 4.8中。
loginClicked
是登录按钮生成的
LoginView
的信号。因此,当按下按钮时,我想将视图更改为
messageView
。您确定
onLoginClicked
信号在您的
LoginView
项目中的某个位置触发了吗?请也发布该文件。我发现了错误…只是我写的是state name
messageView
而不是
messageView