How to create a splash screen with an induced delay: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=How to create a splash screen with an induced delay.=
h1. How to create a splash screen with an induced delay.


We have [http://doc.qt.nokia.com/latest/qsplashscreen.html QSplashScreen] ''[doc.qt.nokia.com]'' which is used to cover up the starting delay of the program. More about splash screen is [http://doc.qt.nokia.com/latest/qsplashscreen.html here] ''[doc.qt.nokia.com]''.<br /> 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 !
We have &quot;QSplashScreen&amp;quot;: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 &quot;here&amp;quot;:http://doc.qt.nokia.com/latest/qsplashscreen.html.<br />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 [http://doc.qt.nokia.com/latest/qthread.html QThread] ''[doc.qt.nokia.com]'' a delay is induced.
Here in this example, using &quot;QThread&amp;quot;:http://doc.qt.nokia.com/latest/qthread.html a delay is induced.
 
<code><br />#include &lt;QApplication&amp;gt;<br />#include &lt;QSplashScreen&amp;gt;<br />#include &lt;qthread.h&amp;gt;<br />#include &quot;mainwindow.h&amp;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(&quot;splash.jpg&amp;quot;);<br /> QSplashScreen splash(pixmap);<br /> splash.show();<br /> MainWindow mainWin;<br /> mainWin.setWindowTitle(&quot;Application&amp;quot;);<br /> I::sleep(5); // splash is shown for 5 seconds<br /> mainWin.showMaximized();<br /> splash.finish(&amp;mainWin);<br /> return app.exec&amp;amp;#40;&amp;#41;;<br />}<br /></code>


Easy! Happy coding!
Easy! Happy coding!


===Categories:===
[[Category:HowTo]]
 
* [[:Category:HowTo|HowTo]]
* [[:Category:snippets|snippets]]

Revision as of 09:50, 24 February 2015

h1. How to create a splash screen with an induced delay.

We have "QSplashScreen&quot;: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&quot;: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&quot;:http://doc.qt.nokia.com/latest/qthread.html a delay is induced.

<br />#include &lt;QApplication&amp;gt;<br />#include &lt;QSplashScreen&amp;gt;<br />#include &lt;qthread.h&amp;gt;<br />#include &quot;mainwindow.h&amp;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(&quot;splash.jpg&amp;quot;);<br /> QSplashScreen splash(pixmap);<br /> splash.show();<br /> MainWindow mainWin;<br /> mainWin.setWindowTitle(&quot;Application&amp;quot;);<br /> I::sleep(5); // splash is shown for 5 seconds<br /> mainWin.showMaximized();<br /> splash.finish(&amp;mainWin);<br /> return app.exec&amp;amp;#40;&amp;#41;;<br />}<br />

Easy! Happy coding!