PDA

View Full Version : CPU consumption



valgaba
1st April 2013, 16:29
Curious phenomenon in CPU consumption.
In the first code
CPU consumption is zero


Timer= new QTimer(this);
connect(Timer, SIGNAL(timeout()), this, SLOT(Update())); // temporizaor horario
Timer->start(10);



void StreamRender::Update(){


QTimer::singleShot(30, this, SLOT(render()));

if (isFinal())
{
//if(Timer->isActive ())
// {
Timer->stop();
emit Finish();
// }
}



}


second code
CPU consumption of 10

void StreamRender::Update(){



if (isFinal())
{
//if(Timer->isActive ())
// {
Timer->stop();
emit Finish();
// }
}

render();

}


Any theories on this consumption.
regards

d_stranz
1st April 2013, 23:19
Because in the first version of Update() that you posted, the single-shot timer does not fire until after the control returns to the event loop, so render() is never called in the Update() method. Also in that code, "Timer" refers to a different instance of QTimer; the call to QTimer::singleShot() creates a temporary QTimer instance that is destroyed once it times out and executes the render() slot.

In the second version of Update(), render() is always called.

Nothing curious about it. The two versions of your code are doing exactly what you've told them to do.