How to create a splash screen with an induced delay: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
h1. How to create a splash screen with an induced delay. | h1. How to create a splash screen with an induced delay. | ||
We have | We have "QSplashScreen":http://doc.qt.nokia.com/latest/qsplashscreen.html which is used to cover up the starting delay of the program. More about splash screen is "here":http://doc.qt.nokia.com/latest/qsplashscreen.html. | ||
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 | Here in this example, using "QThread":http://doc.qt.nokia.com/latest/qthread.html a delay is induced. | ||
<code> | <code> | ||
#include <QApplication> | |||
#include <QSplashScreen> | |||
#include <qthread.h> | |||
#include "mainwindow.h" | |||
class I : public QThread | class I : public QThread | ||
{ | |||
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> | |||
Easy! Happy coding! | Easy! Happy coding! | ||
[[Category:HowTo]] | [[Category:HowTo]] |
Revision as of 10:11, 25 February 2015
h1. How to create a splash screen with an induced delay.
We have "QSplashScreen":http://doc.qt.nokia.com/latest/qsplashscreen.html which is used to cover up the starting delay of the program. More about splash screen is "here":http://doc.qt.nokia.com/latest/qsplashscreen.html. 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":http://doc.qt.nokia.com/latest/qthread.html 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();
}
Easy! Happy coding!