maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   [Qt] Animation - Big CPU consumption (https://talk.maemo.org/showthread.php?t=50753)

Figa 2010-04-22 14:02

[Qt] Animation - Big CPU consumption
 
Please look at this code:
Code:

QPropertyAnimation *animation = new QPropertyAnimation(item, "pos");
                animation->setDuration(199);
                animation->setStartValue(QPointF(20,20));
                animation->setEndValue(QPointF(20,40));
                animation->start();

I have this code in function. This function is called every 200ms. It takes out about 90% CPU. What is wrong? Thx for your replies.

attila77 2010-04-22 14:24

Re: [Qt] Animation - Big CPU consumption
 
Are you sure about the 200ms ? That's like 5 steps in a second. IIRC The default should be around 40-50ms (so you get 25+ fps).

Figa 2010-04-22 14:32

Re: [Qt] Animation - Big CPU consumption
 
Yes I am sure. It is in QTimer and I start it as timer->start(200);

Rob1n 2010-04-22 14:35

Re: [Qt] Animation - Big CPU consumption
 
So, every 200ms you're creating a new animation that runs for 300ms?

timoph 2010-04-22 14:37

Re: [Qt] Animation - Big CPU consumption
 
If I understood that function correctly you are moving some item 20 pixels down 5 times a second. Or do you use it to move different items?

Anyway it looks like you are creating a new QPropertyAnimation object 5 times a second. You could create the object elsewhere (e.g. as a class member) and use it's pointer in the function.

On a side note, the animation duration is longer than the interval of the function calls.

Hard to give any other comments without more details about the purpose of the function and you application.

Figa 2010-04-22 14:38

Re: [Qt] Animation - Big CPU consumption
 
Sry bad example time is changeable. Duration is 199ms.

timoph 2010-04-22 14:44

Re: [Qt] Animation - Big CPU consumption
 
You don't need a QTimer to do an infinite loop for QPropertyAnimation.

Just create the animation once and set
Code:

animation->setLoopCount(-1);
http://doc.qt.nokia.com/4.6/qabstrac...loopCount-prop

Figa 2010-04-22 18:06

Re: [Qt] Animation - Big CPU consumption
 
thx, i have timer because i need timer for other action. ok i will try it when i will come to home. i am not sure if it will work because i need to change parameters of animation

Figa 2010-04-22 19:23

Re: [Qt] Animation - Big CPU consumption
 
I try it and It isnt good. ANimation is created one. And cpu consumption is 70-80%.

mikec 2010-04-22 19:25

Re: [Qt] Animation - Big CPU consumption
 
Have you got an OpenGL ES renderer. (not even sure thats allowed)


All times are GMT. The time now is 18:08.

vBulletin® Version 3.8.8