hi,
i m showing a splash screen before my application starts. The splash screen has a loading icon(a gif image). After showing the splash screen, there is some heavy processing going on because of which the loading icon doesnt animate(it stays in one single frame until the application starts). Next thing i tried was to place qApp->processEvents() at various places inside the "heavy processing code". This makes the loading icon move a bit intermittently but still its not smooth. So next thing i tried was to start a thread at the beginning of the application and have a timer run there, on each timeout of which, qApp->processEvents() will be called. But with this code, loading icon doesnt move at all. Here is the code...
Code:
#include "mythread.h" #include <QTimer> #include <QApplication> { } MyThread::~MyThread() { } void MyThread::run() { connect(timer, SIGNAL(timeout()), this, SLOT(callProcessEvents())); timer->start(100); exec(); } void MyThread::callProcessEvents() { qApp->processEvents(); }
Code:
#include <QLabel> #include <QMovie> #include <QSplashScreen> #include <QEventLoop> #include <QTimer> #include <QBitmap> #include "splashthread.h" #include "mythread.h" int main(int argc, char *argv[]) { MyThread *th = new MyThread(NULL); th->start(); th->moveToThread(th); QSplashScreen screen(QPixmap("C:\\Documents and Settings\\am002bh\\Desktop\\error-checkin.PNG"), Qt::WindowStaysOnTopHint); movie->jumpToFrame(movie->frameCount()); label.setMask(WinMask.mask()); label.setMovie(movie); movie->start(); screen.show(); //sm heavy processing code th->quit(); screen.close();
what am i missing..if i call qApp->processEvents from inside the "heavy processing code", the loading icon animates..if i call that from another thread, it doesnt move at all..i cant start a timer from inside the main function either(which is why i use another thread). i need this loading icon to animate at all times untail the appliction loads(heavy processing code execution is done). Any threading gurus, please let me know how to correctly do this.
Thanks in Advance!
Amulya