You are not logged in.


Thursday, May 17th 2007, 12:34am

Question about running a QMovie in its own thread

Hi all,

I have a QMovie that I'd like to have run smoothly by running it from it's own thread. The current situation is when the application is working, the QMovie animation stutters. I attempted to write a super simple class extending from QThread but alas it's not working. Anyone have experience with this? BTW, I'm using Qt 4.2.

Any help would be greatly appreciated.


P.S. Here's a bit of the code I wrote:

class FwMoviePlayer : public QThread

void run();
void exit();
void setAnimation(QMovie *movie);
QMovie* returnAnimation();

QMovie *mpMovie;

void FwMoviePlayer::run()

void FwMoviePlayer::exit()

void FwMoviePlayer::setAnimation(QMovie *movie)
mpMovie = movie;

QMovie* FwMoviePlayer::returnAnimation()
return mpMovie;

This post has been edited 1 times, last edit by "tim_nitram" (May 17th 2007, 1:13am)



Posts: 52

Location: Romania

  • Send private message


Saturday, May 19th 2007, 10:57pm

First thing: QThread::exit is not virtual so overriding it will cause the base class member to be called when using a polymorphic type.
Advice: use your own stop function and call it instead of exit.

Second thing:
QMovie uses internally a QTimer.
QTimer posts events in the parent thread event loop. The problem, is that your thread ( unlike the main GUI thread ) does not have and event loop because you did not start one.
You can start the event loop with QThread::exec().

Third thing: in run() you call QMovie::start(). But QMovie::start will exit immediately and therefore run will finish and your thread will exit. :) Yeah.

I suggest reading again in Assistant how QMovie has to be used.
It is an asynchronous objects, state based. This means that it will emit signals when it switches states, etc.
You have to synchronize with it by connecting to its signals. If you do this correctly I doubt you will need a thread to play it.

Could we see your initial code ( without the worker thread )?