At the startup of a Qt program, I want to display a QSplashScreen. Maybe it's too fast to get the image. But how can i make the image to last for 2 seconds.
I'm a greenhand, Thanks!
Printable View
At the startup of a Qt program, I want to display a QSplashScreen. Maybe it's too fast to get the image. But how can i make the image to last for 2 seconds.
I'm a greenhand, Thanks!
Hi,
maybe you can connect a QTimerto a splashscreen slot. But in general you should be happy that your app starts so fast ;)
Code:
int main(int argc, char *argv[]) { splash->show(); MyApp mainwindow; return app.exec(); }
Thanks for your reply.
But the main problem is that I can't see the image. Even I can make it to delay 2s, but the startup picture didn't turn up.
What's the problem? Can anyone help? Thanks
Hi,
hard to guess without code ;)
Thanks for your advice.
Code:
#include <QApplication> #include <QSplashScreen> //#include <QThread> //#include<QTimer> #include<ctime> #include "mainwindow.h" /* class SleeperThread : public QThread { public: static void msleep(unsigned long msecs) { QThread::msleep(msecs); } }; */ int main(int argc, char *argv[]) { splash->show(); //splash->showMessage( "Initializing..." ); // app.processEvents(); //...................... MainWindow mainWin; splash->showMessage( "Creating Widgets Page..." ); app.processEvents(); splash->showMessage( "Creating Database Page..." ); app.processEvents(); splash->showMessage( "Creating Games Page..." ); app.processEvents(); // SleeperThread::msleep(2000); time_t t; t = time(NULL); //QTimer::singleShot(2500, splash, SLOT(close())); //QTimer::singleShot(2500, &mainWin, SLOT(show())); mainWin.show(); while( difftime(time(NULL),t) < 5.0 ) { } splash->finish(&mainWin); delete splash; return app.exec(); }
This time, I changed my code and alse set up my qrc file. But the program just show a left top rectangle area of the program instead of the image. How can i make image show?
I will appreciate any reply. Thanks
Hi,
did you add qrc file to the project file and does it have the correct path prefix?
Thanks! In fact I had done all the things. But I found that the following code did make shown the startup images. But the image under the program, So I can't see the startup image. Thanks
Code:
#include <QApplication> #include<QTimer> #include <QSplashScreen> #include "mainwindow.h" int main(int argc, char *argv[]) { splash->show(); MainWindow mainWin; mainWin.show(); return app.exec(); }
You shouldnt be calling mainWin.show() since it will show after timer times out.
Still you can have the following sequence too -
Hope it works :)
i dont think mainWin should be shown before the splashscreen..after all, the primary reason of using a splashscreen is to show smth until the main window will show..thus, just removing the mainWin.show should work..also u can have a bit of delay in closing the splash and showing the mainWin..so, if i were u, i'd write
By the way, QSplashScreen hides automatically when you click on it. There's no need to delay showing of the main window when the splash screen was clicked away, right?
I said u need call mainWindow.show(); u were going to show main window after timer times out.Quote:
hanks. But I just want the splash to show up before the app
Also in above post, did u call splash.show() ?
Code:
int main(int argc, char *argv[]) { splash->show(); MainWindow mainWin; return app.exec(); }
ok, this code is working
Code:
#include <QtGui/QApplication> #include "qtnetwork.h" #include<QTimer> #include <QSplashScreen> #include <QMainWindow> int main(int argc, char *argv[]) { splash->show(); QMainWindow mainWin; return a.exec(); }
i have used QMainWindow and instead of using a qrc, i have used a straight path..so either u have a problem with ur qrc or mainwindow itself
Thanks all of you.
I made a mistake. There are two winMain.show();
QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainWin, SLOT(show()));
mainWin.show();