How to capture a signal in QML?

后端 未结 4 1937
南方客
南方客 2021-02-08 04:50

How I can send s signal from one qml component to another?

Below is an example:

Rectangle {
    id: main
    width: 360; height: 360
    signal clicked()         


        
4条回答
  •  孤街浪徒
    2021-02-08 05:37

    You should use connect() method of component's signals (signals themselves are objects).

    function clickHandler() {
        console.log('main clicked')
    }
    Component.onCompleted: {
        main.clicked.connect(clickHandler)
    }
    

    See http://developer.qt.nokia.com/doc/qt-4.8/qmlevents.html

提交回复
热议问题