Congratulations to our 2022 Qt Champions!

[Solved] Mouse area onClicked problem.

  • I'm trying follow "this tutorial": but I'm getting an error "ReferenceError: Can't find variable: page" when I click the squares. Here's the code (I removed the first and second rectangles for this to make it shorter)
    @import QtQuick 1.0

    Rectangle {
    width: 360
    height: 400
    color: "#515151"

    Image {
        id: logo
        x: 33
        y: 22
        source: "qt.png"
    Rectangle {
        id: middleRect
        x: 274
        y: 155
        width: 64
        height: 64
        color: "#00000000"
        radius: 6
        border.color: "#5f5f5f"
        border.width: 2
        MouseArea {
            id: mouse_area2
            anchors.fill: parent
            onClicked: page.state = 'State2'
    states: [
        State {
            name: "State1"
            PropertyChanges {
                target: logo
                x: middleRect.x
                y: middleRect.y
        State {
            name: "State2"


    Its at the line onClicked: page.state = 'State1' that I get the error.
    It was working last night when I tried but now its not. I don't know what to do.

  • Hi,

    It looks like the top level Rectangle is missing its id (step 4.1 is where this is set).


  • Ah there we go. Thanks for the help I new I was missing something.

Log in to reply