[Qt-qml] QML connections.

Rakesh.Mutharaju at tieto.com Rakesh.Mutharaju at tieto.com
Fri Apr 23 09:36:34 CEST 2010


 
Even the lines,element pertaining to Loader { id: load } are not required.

-rakesh
-----Original Message-----
From: Mutharaju Rakesh 
Sent: Friday, April 23, 2010 10:34 AM
To: 'Martin Jones'; qt-qml at trolltech.com
Subject: RE: [Qt-qml] QML connections.

Thanks Martin.

Well, i figured it out the solution now.,

//pageloader.qml
import Qt 4.7

Item {
    width: 200
    height: 200

    Loader {
        id: load

        B{
            id: bchild
            onBclicked:{
                opacity = 0
                achild.opacity = 1
            }
        }

        A{
            id: achild
            onAclicked:{
                opacity = 0
                bchild.opacity = 1
            }
        }

    }
} 

I guess the Connections part is ok in the below code of A.qml and B.qml

Cheers,
rakesh
-----Original Message-----
From: Martin Jones [mailto:martin.jones at nokia.com]
Sent: Friday, April 23, 2010 3:06 AM
To: qt-qml at trolltech.com
Cc: Mutharaju Rakesh
Subject: Re: [Qt-qml] QML connections.

On Thu, 22 Apr 2010 10:56:38 pm ext Rakesh.Mutharaju at tieto.com wrote:
> Hello,
> 
> I have 3 .qml files pageloader.qml (first file) , A.qml and B.qml. I 
> emit signal from A and B on mouse action and which I am capturing in 
> pageloader.
> 
> Both A and B have signals "signal aclicked()" and "signal bclicked()" 
> which are connected to onAclicked() and onBclicked() signal handlers 
> respectively implemented in pageloader.qml. Both the signals are 
> working when other is commented. But are not received successively.
> 
> //pageloader.qml
> import Qt 4.7
> Item {
>     width: 200
>     height: 200
>     Loader {
>         id:load
>         source: "A.qml"
>         B{
>             onBclicked:{
>                 load.item.opacity = 0
>                 console.log(load.source)
>                 load.source = ""
>                 console.log("B Clicked!")
>                 console.log("B unloaded status !"+load.status)
>                 load.source = "A.qml"
>                 console.log(load.source)
>                 console.log("A loaded status !"+load.status)
>                 load.item.opacity = 1
>             }
>         }
>         A{
>             onAclicked:{
>                 load.item.opacity = 0
>                 console.log(load.source)
>                 load.source = ""
>                 console.log("A Clicked!")
>                 console.log("A unloaded status !"+load.status)
>                 load.source = "B.qml"
>                 console.log(load.source)
>                 console.log("B loaded status !"+load.status)
>                 load.item.opacity = 1
>             }
>         }
>     }
> }
> 
> //A.qml
> import Qt 4.7
> Rectangle {
>     id: rectangleA
>     width: 200
>     height: 200
>     color: "#0000ff"
>     signal aclicked()
>     Text {
>         x: 72
>         y: 67
>         width: 28
>         height: 48
>         text: "A"
>         font.bold: true
>         font.pointSize: 30
>         anchors.horizontalCenter: parent.horizontalCenter
>         anchors.verticalCenter: parent.verticalCenter
>         MouseArea{
>             //id: areaA
>             anchors.bottomMargin: 0
>             anchors.topMargin: 0
>             anchors.leftMargin: 0
>             anchors.rightMargin: 0
>             anchors.fill: parent
>             Connections {
>                 onClicked:{
>                     console.log("A Clicked!")
>                     rectangleA.aclicked()
>                 }
>             }
>         }
>     }
> }
> 
> //B.qml
> import Qt 4.7
> Rectangle {
>     id: rectangleB
>     width: 200
>     height: 200
>     color: "#ff0000"
>     signal bclicked()
>     Text {
>         x: 72
>         y: 67
>         width: 28
>         height: 48
>         text: "B"
>         font.bold: true
>         font.pointSize: 30
>         anchors.horizontalCenter: parent.horizontalCenter
>         anchors.verticalCenter: parent.verticalCenter
>         MouseArea{
>             //id: areaB
>             anchors.bottomMargin: 0
>             anchors.topMargin: 0
>             anchors.leftMargin: 0
>             anchors.rightMargin: 0
>             anchors.fill: parent
>             Connections {
>                 onClicked:{
>                     console.log("B Clicked!")
>                     rectangleB.bclicked()
>                 }
>             }
>         }
>     }
> }
> 
> From the debug log I notice that
> A Clicked!
> 
> file:///Z:/test_trans/A.qml
> 
> A Clicked!
> 
> A unloaded status !0
> 
> file:///Z:/test_trans/B.qml
> 
> B loaded status !1
> 
> B Clicked! ---->>>>>> signal is lost
> 
> Could someone correct me?

This is what is happening:

At startup, you will have 3 children in the Loader.  A (1), which was set as the source in the loader, B (1), which is specified directly as a child of the loader, and another A (2), also specified directly as a child of the loader, so the hierarchy looks like this:

Item
    Loader
        A  (1)
        B (1)
        A  (2)

Note that the default stacking order, with no z value set, is that the last created sibling is on top, so A (2) is the top item and will get the mouse click.

Now when that item is clicked the Loader source,  A (1) will be destroyed, and a new B (2) will be created, and will become the top item, so your hierarchy looks like this:

Item
    Loader
        B (1)
        A  (2)
        B (2)

The next click will go to the newly created B (2), on which you have no handler for its onBClicked signal, so nothing happens.

--
Martin




More information about the Qt-qml mailing list