No, I think the problem is that inside this for loop, the Qt event loop isn't being allowed to run. So what is happening is that all of the frames *are* being jumped to, but because paint events are just stacking up without being handled, all of them are getting removed except for the last one that paints the final frame.
You could add a call to QApplication:: processEvents() inside the loop, but this probably would not give satisfactory results either, since the frames would be displayed as fast as Qt could handle them. So visually all the viewer would be able to see is the last frame because the others flash by too quickly to be "seen" by the user's visual system.
The best solution is probably to use the Qt animation framework to step through the frames, or to implement a QTimer and a timeout() handler that will do it for you:
void MyWidget::showMovie()
{
currentFrame = 0; // member variable
timer.setInterval( 33 ); // "timer" is also a member variable; 33 ms is roughly 30 frames / sec rate
connect( &timer, SIGNAL( timeout() ), this, SLOT( showFrame() ) );
showFrame();
timer.start();
}
void MyWidget::showFrame()
{
if ( currentFrame >= 0 && currentFrame < vec.size() )
{
movie.jumpToFrame( vec.at( currentFrame ) );
currentFrame++;
}
else
{
timer.stop();
}
}
void MyWidget::showMovie()
{
currentFrame = 0; // member variable
timer.setInterval( 33 ); // "timer" is also a member variable; 33 ms is roughly 30 frames / sec rate
connect( &timer, SIGNAL( timeout() ), this, SLOT( showFrame() ) );
showFrame();
timer.start();
}
void MyWidget::showFrame()
{
if ( currentFrame >= 0 && currentFrame < vec.size() )
{
movie.jumpToFrame( vec.at( currentFrame ) );
currentFrame++;
}
else
{
timer.stop();
}
}
To copy to clipboard, switch view to plain text mode
Note that this code displays the movie only once. If you want to loop repeatedly through the animation, replace the timer.stop(); call with currentFrame = 0; movie.jumpToFrame( vec.at( currentFrame ) );
Bookmarks