How to create a splash screen with an induced delay
Jump to navigation
Jump to search
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.
<br />#include <QApplication&gt;<br />#include <QSplashScreen&gt;<br />#include <qthread.h&gt;<br />#include "mainwindow.h&quot;
class I : public QThread<br />{<br />public:<br /> static void sleep(unsigned long secs) {<br /> QThread::sleep(secs);<br /> }<br />};
int main(int argc, char *argv[])<br />{
QApplication app(argc, argv);<br /> QPixmap pixmap("splash.jpg&quot;);<br /> QSplashScreen splash(pixmap);<br /> splash.show();<br /> MainWindow mainWin;<br /> mainWin.setWindowTitle("Application&quot;);<br /> I::sleep(5); // splash is shown for 5 seconds<br /> mainWin.showMaximized();<br /> splash.finish(&mainWin);<br /> return app.exec&amp;#40;&#41;;<br />}<br />
Easy! Happy coding!