[Interest] Understanding attached signals

Nicolás Ulrich nikolaseu at gmail.com
Wed Mar 19 12:40:12 CET 2014


On Wed, Mar 19, 2014 at 8:19 AM, Sze Howe Koh <szehowe.koh at gmail.com> wrote:

> Hi all,
>
> I was playing around with attached signals to learn how they tick.
> Here are two test programs, each with 3 different ways of connecting
> to a signal:
>
> //==========
> import QtQuick 2.2
>
> Rectangle {
>     width: 360
>     height: 360
>
>     Text {
>         text: "Click Me"
>         anchors.centerIn: parent
>
>         MouseArea {
>             id: mouseArea
>             anchors.fill: parent
>             onClicked: console.log("Clicked (Direct signal handler)")
>         }
>     }
>
>     Connections {
>         target: mouseArea
>         onClicked: console.log("Clicked (Connections)")
>     }
>
>     function jsFunction() {
>         console.log("Clicked (JS Function)")
>     }
>     Component.onCompleted: mouseArea.clicked.connect(jsFunction)
> }
> //==========
> //==========
> import QtQuick 2.2
>
> Rectangle {
>     width: 360
>     height: 360
>
>     Rectangle {
>         id: box
>         width: 50
>         height: 50
>         color: "green"
>
>         Drag.active: mouseArea.drag.active
>         Drag.dragType: Drag.Automatic
>         Drag.onDragStarted: console.log("Started (Attached Signal
> Handler)")
>
>         MouseArea {
>             id: mouseArea
>             anchors.fill: parent
>             drag.target: parent
>         }
>     }
>
>     Connections {
>         target: box
>         Drag.onDragStarted: console.log("Started (Connections)")
>     }
>

>     function jsFunction() {
>         console.log("Started (JS Function)")
>     }
>     Component.onCompleted: box.Drag.dragStarted.connect(jsFunction)
> }
> //==========
>
> When run them and click/drag the relevant items, the output I get is:
>
>     Clicked (Direct signal handler)
>     Clicked (Connections)
>     Clicked (JS Function)
>
>     Started (Attached Signal Handler)
>     Started (JS Function)
>
> It looks like the Connections item doesn't activate in the dragging
> test. Could someone explain why that's the case?
>
>
> Thanks!
> Sze-Howe
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>


Have you tried something like this?

    Connections {
        target: box.Drag
        onDragStarted: console.log("Started (Connections)")
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140319/2df09f05/attachment.html>


More information about the Interest mailing list