Signals and Handlers not working!



  • Hello,

    The example below is taken from the http://doc.qt.io/qt-5/qtqml-syntax-signals.html.
    There are two qml files. The signal is in SquareButton.qml and the handler is in the myapplication.qml. When I ran it, it does not do anything when I click the mouse area.
    Can anybody please help me?

    // SquareButton.qml
    Rectangle {
    id: root

    signal activated(real xPosition, real yPosition)
    
    width: 100; height: 100
    
    MouseArea {
        anchors.fill: parent
        onPressed: root.activated(mouse.x, mouse.y)
    }
    

    }

    // myapplication.qml
    SquareButton {
    onActivated: console.log("Activated at " + xPosition + "," + yPosition)
    }


  • Moderators

    Hi! Works for me. Do you get any error messages?

    import QtQuick 2.7
    
    Rectangle {
        id: root
    
        signal activated(real xPosition, real yPosition)
    
        width: 100; height: 100
        color: "blue"
    
        MouseArea {
            anchors.fill: parent
            onPressed: {
                root.activated(mouse.x, mouse.y)
            }
        }
    }
    
    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        SquareButton {
            onActivated: console.log("Activated at " + xPosition + "," + yPosition)
        }
    }
    


  • @Wieland
    Hello,

    I know it is different from the example, but hey it works!
    Thanks!


Log in to reply
 

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