A simple issue



  • Hi,
    It might be a silly question! But if possible please take a look at this project named States.

    main.qml:

    import QtQuick 2.8
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Traffic Lights")
    
        State { }
     }
    

    State.qml:

    import QtQuick 2.8
    
    Rectangle {
        id: root
        width: 150
        height: 250
    
        property color black: '#1f1f21'
        property color red: '#fc3d39'
        property color green: '#53d769'
    
    
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#2ed5fa" }
            GradientStop { position: 1.0; color: "#2467ec" }
        }
    
        Rectangle {
            id: light1
            x: 25; y: 15
            width: 100; height: width
            radius: width/2
            color: root.black
            border.color: Qt.lighter(color, 1.1)
        }
    
        Rectangle {
            id: light2
            x: 25; y: 135
            width: 100; height: width
            radius: width/2
            color: root.black
            border.color: Qt.lighter(color, 1.1)
        }
    
        state: "stop"
        states: [
           State {
                name: "stop"
                PropertyChanges { target: light1; color: root.red }
                PropertyChanges { target: light2; color: root.black }
                PropertyChanges { target: light1; scale: 1.1 }
                PropertyChanges { target: light2; scale: 0.9 }
                },
           State {
                name: "go"
                PropertyChanges { target: light1; color: root.black }
                PropertyChanges { target: light2; color: root.green }
                PropertyChanges { target: light1; scale: 0.9 }
                PropertyChanges { target: light2; scale: 1.1 }
                }
        ]
    
    
        MouseArea {
            anchors.fill: parent
            onClicked: parent.state = (parent.state == "stop" ? "go" : "stop")
        }
    
        transitions: [
            Transition {
                from: "stop"; to: "go"
                   // from: "*"; to: "*"
                ColorAnimation { target: light1; properties: "color"; duration: 2000 }
                ColorAnimation { target: light2; properties: "color"; duration: 2000 }
            }
        ]
    }
    

    It seems that State.qml isn't connected properly. The project shows only a blank window! :(


  • Moderators

    Try renaming State.qml to something which is not already a built-in component of Qt Quick :-)
    (although to be honest QML does support such name shadowing so I think it still should work)



  • @sierdzio
    Hi,
    Thanks. I renamed it to MyState.qml.
    Clean all > run qMake > Rebuild all.
    Still nothing! :(

    0_1511893560542_Capture.PNG


  • Moderators

    @tomy said in A simple issue:

    State { }

    And you have updated that line in main.qml to MyState { }, yes?



  • Hi,
    @tomy i tested your code, its working for me. Could you past you compiler output ?



  • @sierdzio
    Thank you. I'd forgotten it.
    It works now. :)



  • @LeLev

    That's it.

    0_1511902519690_Capture.PNG



  • @tomy
    On the bottom of your screen (bottom of qt creator) you have tabs, select Tab 4 : "Compile Output", you are showing Tab 3: "Application Output"



  • @LeLev
    Sorry, you'r right! :)

    0_1511904308232_Capture.PNG


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.