[Qt-qml] Animation events

Jason H scorp1us at yahoo.com
Mon Sep 27 13:53:16 CEST 2010


Thanks, I got it working. It's onCompleted. And I'm using your alias trick.

Is there documentation on how to use signals/slots from QML? I looked through 
and didn't see anything on how to define your own signals in QML




----- Original Message ----
From: "michael.brasser at nokia.com" <michael.brasser at nokia.com>
To: scorp1us at yahoo.com
Cc: qt-qml at trolltech.com
Sent: Sun, September 26, 2010 7:45:09 PM
Subject: Re: [Qt-qml] Animation events

Hi Jason,

Sorry, I should have been more explicit in that example. "onAnimationFinished" 
was meant as a hypothetical signal -- you can define any signals you like on the 
item being loaded by the Loader, and then connect to them using Connections. 
Here's a small, but complete example of how this could work with animations (the 
animation triggers a signal on the top-level item in the component when it is 
finished, which gets handled by the Connections element at the Loader level):

// GreenRect.qml
import Qt 4.7
Rectangle {
    id: theRect
    signal animationCompleted
    width: 100; height: 100
    color: "green"
    SequentialAnimation {
        running: true
        onRunningChanged: if (!running) animationCompleted()
        NumberAnimation { target: theRect; property: "width"; to: 300; duration: 
1000 }
    }
}

// main.qml
import Qt 4.7
Rectangle {
    width: 300
    height: 100
    Loader {
        id: loader
        source: "GreenRect.qml"
    }
    Connections {
        target: loader.item
        onAnimationCompleted: console.log("animation finished")
    }
}

Regards,
Michael

On 24/09/2010, at 10:13 PM, ext Jason H wrote:

> Thanks Michael.
> 
> I can't seem to find my animation.
> 
> the A.qml is:
> Rectangle {
>    id: redRect
> SequentialAnimation {
>       id: mainAnimation
> }
> }
> 
> 
> When I specify the target, I get 
> "Unable to assign [undefined] to QObject* 
> target" and 
> "QML Connections: Cannot assign to non-existent property 
> "onAnimationFinished"
> 
> I've tried various targets. 
> 
> ----- Original Message ----
> From: "michael.brasser at nokia.com" <michael.brasser at nokia.com>
> To: scorp1us at yahoo.com
> Cc: qt-qml at trolltech.com
> Sent: Fri, September 24, 2010 1:56:10 AM
> Subject: Re: [Qt-qml] Animation events
> 
> On 24/09/2010, at 11:47 AM, ext Jason H wrote:
>> I know I've asked something like this before, but I've never gotten anything to 
>>
>> 
>> 
>> 
>> work like I wanted. Plus it's mutated over time.
>> I have a collection of components. I will start an animation in the first 
>> component. When the animation completes, I want it to consult an external 
>> source 
>> 
>> 
>> (database, web URL, etc) to decide what component to run next, then run its 
>> animation. And so on.
>> 
>> But I don't want one component calling the next because the call stack would 
>> just keep increasing, I want a root element doing it 
>> 
>> all.
>> //main.qml
>> Rectangle{ 
>>   id: root
>>   width: 860
>>   height: 540
>>   Loader { source: "A.qml" }
>>   Loader { source: "B.qml" }
>>   function pickNext()
>>   {
>>       // pick nect
>>   }
>> }
>> but the animation finishes and has no way (that I found) for the 
>> animation in A.qml to inform the root element that it is time to pick the 
>> next one.
>> the Loader does not set the parent property of the loaded qml item.
>> 
>> If this were C++ I'd have the A.qml emit a signal, which would be caught by 
>> root. 
> 
> Hi,
> 
> You should be able to use the Connections element to respond to signals emitted 
>
> by a Loader's item:
> 
> //main.qml
> Rectangle{ 
>   id: root
>   width: 860
>   height: 540
>   Loader { id: loader1; source: "A.qml" }
>   Loader { id: loader2; source: "B.qml" }
>   Connections {
>      target: loader1.item
>      onAnimationFinished: pickNext()
>   }
>   function pickNext()
>   {
>       // pick nect
>   }
> }
> 
> Regards,
> Michael
> 
> 
> 


      



More information about the Qt-qml mailing list