How to create a splash screen with an induced delay: Difference between revisions
Jump to navigation
Jump to search
AutoSpider (talk | contribs) (Decode HTML entity names) |
(Cleanup) |
||
Line 1: | Line 1: | ||
{{ | {{LangSwitch}} | ||
[[Category:HowTo]] | |||
We have {{DocLink|QSplashScreen}} which is used to cover up the starting delay of the program. Some times the programs might be quick enough, so that the splash screen may not be visible. We may induce some delay to show the splash, as a decoration! | |||
Here in this example, using {{DocLink|QThread}} a delay is induced. | |||
Here in this example, using | |||
<code> | <code> | ||
Line 16: | Line 14: | ||
{ | { | ||
public: | public: | ||
static void sleep(unsigned long secs) { QThread::sleep(secs); } | |||
}; | }; | ||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
{ | { | ||
QApplication app(argc, argv); | |||
QApplication app(argc, argv); | QPixmap pixmap("splash.jpg"); | ||
QSplashScreen splash(pixmap); | |||
splash.show(); | |||
MainWindow mainWin; | |||
mainWin.setWindowTitle("Application"); | |||
I::sleep(5); // splash is shown for 5 seconds | |||
mainWin.showMaximized(); | |||
splash.finish(&mainWin); | |||
return app.exec(); | |||
} | } | ||
</code> | </code> | ||
Revision as of 18:57, 28 June 2015
En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh
We have QSplashScreen which is used to cover up the starting delay of the program. Some times the programs might be quick enough, so that the splash screen may not be visible. We may induce some delay to show the splash, as a decoration!
Here in this example, using QThread a delay is induced.
#include <QApplication>
#include <QSplashScreen>
#include <qthread.h>
#include "mainwindow.h"
class I : public QThread
{
public:
static void sleep(unsigned long secs) { QThread::sleep(secs); }
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPixmap pixmap("splash.jpg");
QSplashScreen splash(pixmap);
splash.show();
MainWindow mainWin;
mainWin.setWindowTitle("Application");
I::sleep(5); // splash is shown for 5 seconds
mainWin.showMaximized();
splash.finish(&mainWin);
return app.exec();
}