PDA

View Full Version : Animating QSplashScreen



pssss
1st September 2011, 22:47
Hi,

I'm trying to animate QSplashScreen to show that it's not blocked, most of the loading time is spent in the MainWindow constructor, specifically creating 2 instances of Phonon::VideoWidget. I have subclassed QSplashScreen and reimplemented drawContents(). On the splash screen I want to show a simple moving gradient but I'd be happy to just show a few blinking dots as in "Loading...".

I'm using timers and slots to animate it, these must be in an event loop but before the MainWindow is created I can't use the QApplication's event loop, so one option would be to use a local QEventLoop but this doesn't make much sense because it would have to be before the call to the MainWindow constructor, which would stop this constructor from being called until the local event loop is finished.

Calling qApp->processEvents() several times around the code is not an option because the operations that take the longest during startup are only 2 VideoWidget constructors, the time taken by the rest is almost negligible. I've tried with a QThread with the highest priority but I think the priority is ignored and the timeout() signals aren't processed while the VideoWidget objects are being created in the MainWindow constructor which makes the animation bumpy.

I've almost given up hope that splash screens can be animated succesfully in Qt but I decided to ask here.

Thanks in advance.

Rachol
2nd September 2011, 13:47
There is nothing that you can do as far as I know... Would you like to have a splashScreen being a separated app? then you can use QSharedMemory to handle its state...

yeye_olive
2nd September 2011, 14:08
It is likely nothing can be done to solve your problem because:
1) all the GUI work must be done in the same thread, which means that the VideoWidget constructor will freeze the rest of the GUI;
2) having the event loop running will not help unless the VideoWidget constructor itself calls e.g. qApp->processEvents().

On a side note, it is in general a bad idea to do some heavy work in the constructor of the main window. You should instead move the time-consuming code to a private slot initialize() and schedule its execution as soon as event processing starts by adding, for instance, the following line to the window's constructor:

QTimer::singleShot(0, this, SLOT(initialize()));

pssss
3rd September 2011, 12:39
hen you can use QSharedMemory to handle its state

That's a good idea.


On a side note, it is in general a bad idea to do some heavy work in the constructor of the main window. You should instead move the time-consuming code to a private slot initialize() and schedule its execution as soon as event processing starts by adding, for instance, the following line to the window's constructor:

Thanks, I wasn't aware of this.