PDA

View Full Version : make QMovie move while in blocking function call.



33333
16th October 2011, 01:47
Hello, I want to throw up a status notification while doing a network check which involves blocking system calls and may take some time. The notification will take the form of a message like "doing NW check" and a strobing animation. THis is the code:

QMovie * strobe = new QMovie( "./strobe.gif" );
QLabel * label = new QLabel( "Checking Networking ... " );
QLabel * field = new QLabel();
strobe->start();
field->setMovie( strobe );
systemCheckPage->addRow( label, field );
repaint();
qApp->processEvents();
doNetWorkCheck(); //blocks
...

Problem is - I think - the movie relies on the event loop. Not even the text label is shown. The repaint() and processEventd() dont do sqwat. Is there a better graphics class I could use that works without the event loop or another simple way around this?

Thanks.

boudie
16th October 2011, 14:04
To be effective, processEvents() should be called from within the blocking function; in this case doNetworkCheck().
If there is to much delay in doNetworkCheck(), then maybe you should consider running it in its own thread.

33333
17th October 2011, 04:20
Thanks for reply.

Found solution. So yeah I think threading is the general solution here unfortunately. In my case since Im calling executable processes and waiting for return I can use QProcess, and connect the finished() signal to a handler. I had not realized QProcess could be used like this.

Thanks.