Results 1 to 9 of 9

Thread: QMovie displays only last frame

  1. #1
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QMovie displays only last frame

    I am trying to create an animation from an animated gif, where I jump to a particular frame based on an input from within a loop (see below). However, only the last frame is being displayed and think I need to flush the buffer, but don't know how Or maybe there is some other method to show the individual frames inside the loop.

    Qt Code:
    1. for(int i = 0; i < vec.size(); i++)
    2. {
    3. movie.jumpToFrame( vec.at(i) );
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QMovie displays only last frame

    Check the size of the vector at runtime.
    It might actually be holding only one frame.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,345
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: QMovie displays only last frame

    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:

    Qt Code:
    1. void MyWidget::showMovie()
    2. {
    3. currentFrame = 0; // member variable
    4. timer.setInterval( 33 ); // "timer" is also a member variable; 33 ms is roughly 30 frames / sec rate
    5. connect( &timer, SIGNAL( timeout() ), this, SLOT( showFrame() ) );
    6. showFrame();
    7. timer.start();
    8. }
    9.  
    10. void MyWidget::showFrame()
    11. {
    12. if ( currentFrame >= 0 && currentFrame < vec.size() )
    13. {
    14. movie.jumpToFrame( vec.at( currentFrame ) );
    15. currentFrame++;
    16. }
    17. else
    18. {
    19. timer.stop();
    20. }
    21. }
    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 ) );
    Last edited by d_stranz; 2nd July 2012 at 17:56.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QMovie displays only last frame

    am trying to create an animation from an animated gif, where I jump to a particular frame based on an input from within a loop (see below).
    Why are you using a loop at all if what you want is to jump to a particular frame?

    @d_stranz
    To show the movie you can just do: movie.start();
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,345
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: QMovie displays only last frame

    To show the movie you can just do: movie.start();
    From the context of the OP, I assumed that images from the animated GIF were not contained in a QMovie, but in some other data structure which had to be accessed manually. If it is in fact a QMovie, then movie.start() would obviously be the right choice.

    It's Monday morning here, not fully awake yet.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QMovie displays only last frame

    From the context of the OP, I assumed that images from the animated GIF were not contained in a QMovie, but in some other data structure which had to be accessed manually.
    But then it wouldn't make much sense to jumpToFrame() in the movie, if it is not containing the frames...
    Indeed the OP's choice to loop through the movie while wanting to jump to a specific frame eludes me.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMovie displays only last frame

    I am using the loop and jumpToFrame() because the the frame I want to jump to isn't in sequential order (2, 5, 1, 10, 30, 6 ...).

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QMovie displays only last frame

    I am using the loop and jumpToFrame() because the the frame I want to jump to isn't in sequential order (2, 5, 1, 10, 30, 6 ...).
    Still, you are jumping to many frames in the loop, not to *a* frame, and you see the last one you jumped to.
    First loop over your vector, find your desired frame index, and then, outside the loop do the jump to that index.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,345
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: QMovie displays only last frame

    I am using the loop and jumpToFrame() because the the frame I want to jump to isn't in sequential order (2, 5, 1, 10, 30, 6 ...).
    Well, then the QTimer method I suggested would let you do that. Whatever you choose to do, you have to let Qt's event loop process the paint event generated by the jumpToFrame() call, otherwise you'll only see a frame change when Qt is finally allowed to process events. The QTimer method does that automatically for you since the whole thing is handled within the event loop concept.

Similar Threads

  1. QGL: Tearing in Fullscreenmode with two displays
    By beetleskin in forum Qt Programming
    Replies: 0
    Last Post: 18th January 2011, 18:16
  2. Qt displays large size jpg
    By omegas in forum Qt Programming
    Replies: 14
    Last Post: 22nd April 2010, 06:07
  3. Multiple displays on X11
    By alisami in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2009, 18:25
  4. Previous frame inner to this frame(corrupt stack?)
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 28th May 2007, 02:35
  5. Previous frame inner to this frame(corrupt stack?)
    By coralbird in forum Qt Programming
    Replies: 17
    Last Post: 29th April 2006, 02:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.