PDA

View Full Version : launch in a gif via QMovie and QThread



desch
20th February 2008, 06:38
Hi,

I try to launch a throbber (just a gif) during intensive process.

1) I tried to launch it directly like


QMovie movie(":/throbber.gif");
movie.start();
label->setMovie(movie);

...
//intensive process


The gif doesn't move at all during process and start moving after the intensive process :D

2)Using a QThread


CThreadMovie::CThreadMovie(QMovie * movie)
{
_movie = movie;
}

void CThreadMovie::run()
{
if (_movie != NULL)
_movie->start();

exec();
}


I launch with this interface:


QMovie * movie = new QMovie(":/throbber");
labelThrobber->setMovie(movie);

// create Thread instance
_threadMovie = new CThreadMovie(movie);

_threadMovie->start();

It doesn't work ;)

So the questions

What do I do wrong?
What should I do?

Thanks to all

David

jpn
20th February 2008, 07:28
You must not touch widgets in worker threads. Either handle that "intensive process" in a worker thread and deliver results to main GUI thread with signals and slots (or custom events) or call QCoreApplication::processEvents() every now and then in the middle of the "intensive process".

desch
20th February 2008, 08:51
OK

As we have made all our process in one thread; it's not a simple work to change the complete application to Muti Thread

So for just running a Gif Is there a simple way (something very light)?

Thanks

David

jpn
20th February 2008, 09:02
You must let the application process its events meanwhile you do intensive work which blocks the event loop. So as I said, call QCoreApplication::processEvents() every now and then during the intensive work.