Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create Slpash Screen
Forum Update on Monday, May 27th 2025

Create Slpash Screen

Scheduled Pinned Locked Moved Solved General and Desktop
splashscreencreateqt 5.4.1
9 Posts 5 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M4RZB4Ni
    wrote on 25 Apr 2016, 10:07 last edited by M4RZB4Ni
    #1

    Hi,
    I want To Create A splash Screen for My Application
    i wrote This Code But when i start app Instantly Viewed and THEN instantly
    Non-View!
    this is my code and what i must do to set show time off splash screed?

    int main(int argc, char *argv[])
    {
     QApplication app(argc, argv);
     QSplashScreen *splash = new QSplashScreen;
     splash->setPixmap(QPixmap(":/images/splash.png"));
     splash->show();
     Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
     splash->showMessage(QObject::tr("Setting up the main window..."),
     topRight, Qt::white);
     MainWindow mainWin;
     splash->showMessage(QObject::tr("Loading modules..."),
     topRight, Qt::white);
     loadModules();
     splash->showMessage(QObject::tr("Establishing connections..."),
     topRight, Qt::white);
     establishConnections();
     mainWin.show();
     splash->finish(&mainWin);
     delete splash;
     return app.exec();
    }
    

    Thanks
    M4RZB4Ni

    X 1 Reply Last reply 26 Apr 2016, 08:56
    0
    • R Offline
      R Offline
      Ratzz
      wrote on 25 Apr 2016, 10:16 last edited by Ratzz
      #2

      Hi might be this,

          QApplication app(argc, argv);
          QPixmap pixmap(":/new/prefix1/Icons/SplashScreen.png");
          QSplashScreen splash(pixmap);
          splash.show();
          //This line represents the alignment of text, color and position
          splash.showMessage(QObject::tr("Initiating..."),Qt::AlignLeft, Qt::white);
      
          app.processEvents();
          Sleep(3000);
      
          MainWindow win;
          win.showMaximized();
          splash.finish(&win);
          return app.exec();

      --Alles ist gut.

      1 Reply Last reply
      1
      • M M4RZB4Ni
        25 Apr 2016, 10:07

        Hi,
        I want To Create A splash Screen for My Application
        i wrote This Code But when i start app Instantly Viewed and THEN instantly
        Non-View!
        this is my code and what i must do to set show time off splash screed?

        int main(int argc, char *argv[])
        {
         QApplication app(argc, argv);
         QSplashScreen *splash = new QSplashScreen;
         splash->setPixmap(QPixmap(":/images/splash.png"));
         splash->show();
         Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
         splash->showMessage(QObject::tr("Setting up the main window..."),
         topRight, Qt::white);
         MainWindow mainWin;
         splash->showMessage(QObject::tr("Loading modules..."),
         topRight, Qt::white);
         loadModules();
         splash->showMessage(QObject::tr("Establishing connections..."),
         topRight, Qt::white);
         establishConnections();
         mainWin.show();
         splash->finish(&mainWin);
         delete splash;
         return app.exec();
        }
        
        X Offline
        X Offline
        xeggsy
        wrote on 26 Apr 2016, 08:56 last edited by xeggsy
        #3

        @M4RZB4Ni I think you probably just copied that code from: http://www.qtcentre.org/archive/index.php/t-45572.html. Even though that is not important it does indicate to me that you have not really searched for an answer on your own. Anyway, I would say the easiest way to see whether the splash screen is working properly (testing it) is by using the QTest namespace as follows:

        #include "MyClass.h" // #include "MainWindow.h" in your case
        #include <QtGui/QApplication>
        #include <QSplashScreen>
        #include <QTest> // The testing namespace
        
        int main(int argc, char *argv[])
        {
        	QApplication app(argc, argv);
        	QSplashScreen *splash = new QSplashScreen; // May also be allocated on the stack instead
        	splash->setPixmap(QPixmap(":MyClass/Resources/images/Qt Logo.png")); // Replace with a path to your own image
        	splash->show();
        
        	Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
        	splash->showMessage(QObject::tr("Setting up the main window..."), topRight, Qt::white);
        	QTest::qSleep(1000); // Sleeps the application for 1 second and blocks processing of events
        	
        	splash->showMessage(QObject::tr("Loading modules..."), topRight, Qt::white);
        	MyClass myClass; // Is MainWindow win in your case
        	QTest::qSleep(1000);
        	//myClass.loadModules(); Have not implemented this function
        	
        	splash->showMessage(QObject::tr("Establishing connections..."), topRight, Qt::white);
        	QTest::qSleep(1000);
        	//myClass.establishConnections(); Idem
        
        	myClass.show();
        	splash->finish(&myClass);
        	delete splash;
        	
        	return app.exec();
        }
        

        The calls to QTest::qSleep(1000) sleep the application for a 1000 milliseconds (no event processing). You can also replace it with QTest::qWait(1000) (with event processing). AFAIK there is no specific function that is part of the QSplashScreen library which you can use to set a display time for the splash screen.

        If you always want to sleep the application for a few seconds to show the splash screen and thereby temporarily prevent the execution of the rest of your program then I would use @Ratzz method.

        M 1 Reply Last reply 26 Apr 2016, 13:48
        1
        • V Offline
          V Offline
          VRonin
          wrote on 26 Apr 2016, 12:49 last edited by
          #4

          splash->finish(&mainWin); does not block the main thread.
          instead of calling delete splash; directly, use splash->setAttribute(Qt::WA_DeleteOnClose); (better if you set the attribute before calling show)

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • X xeggsy
            26 Apr 2016, 08:56

            @M4RZB4Ni I think you probably just copied that code from: http://www.qtcentre.org/archive/index.php/t-45572.html. Even though that is not important it does indicate to me that you have not really searched for an answer on your own. Anyway, I would say the easiest way to see whether the splash screen is working properly (testing it) is by using the QTest namespace as follows:

            #include "MyClass.h" // #include "MainWindow.h" in your case
            #include <QtGui/QApplication>
            #include <QSplashScreen>
            #include <QTest> // The testing namespace
            
            int main(int argc, char *argv[])
            {
            	QApplication app(argc, argv);
            	QSplashScreen *splash = new QSplashScreen; // May also be allocated on the stack instead
            	splash->setPixmap(QPixmap(":MyClass/Resources/images/Qt Logo.png")); // Replace with a path to your own image
            	splash->show();
            
            	Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
            	splash->showMessage(QObject::tr("Setting up the main window..."), topRight, Qt::white);
            	QTest::qSleep(1000); // Sleeps the application for 1 second and blocks processing of events
            	
            	splash->showMessage(QObject::tr("Loading modules..."), topRight, Qt::white);
            	MyClass myClass; // Is MainWindow win in your case
            	QTest::qSleep(1000);
            	//myClass.loadModules(); Have not implemented this function
            	
            	splash->showMessage(QObject::tr("Establishing connections..."), topRight, Qt::white);
            	QTest::qSleep(1000);
            	//myClass.establishConnections(); Idem
            
            	myClass.show();
            	splash->finish(&myClass);
            	delete splash;
            	
            	return app.exec();
            }
            

            The calls to QTest::qSleep(1000) sleep the application for a 1000 milliseconds (no event processing). You can also replace it with QTest::qWait(1000) (with event processing). AFAIK there is no specific function that is part of the QSplashScreen library which you can use to set a display time for the splash screen.

            If you always want to sleep the application for a few seconds to show the splash screen and thereby temporarily prevent the execution of the rest of your program then I would use @Ratzz method.

            M Offline
            M Offline
            M4RZB4Ni
            wrote on 26 Apr 2016, 13:48 last edited by
            #5

            @xeggsy
            tnx but your code show below error:
            error: undefined reference to `_imp___ZN5QTest6qSleepEi'
            what i must do?

            Thanks
            M4RZB4Ni

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 26 Apr 2016, 21:48 last edited by
              #6

              Hi,

              Never use the QtTest module in production code. It's a framework for unit testing.

              Out of curiosity, why do you want to slow down your application startup to show a splash screen ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              M 1 Reply Last reply 27 Apr 2016, 15:29
              0
              • S SGaist
                26 Apr 2016, 21:48

                Hi,

                Never use the QtTest module in production code. It's a framework for unit testing.

                Out of curiosity, why do you want to slow down your application startup to show a splash screen ?

                M Offline
                M Offline
                M4RZB4Ni
                wrote on 27 Apr 2016, 15:29 last edited by M4RZB4Ni
                #7

                @SGaist
                hi,
                tnx but i just need a source code for splash screen
                can you write a sample code for me please?

                Thanks
                M4RZB4Ni

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Apr 2016, 19:36 last edited by
                  #8

                  This will give you the base to get started:

                  QSplashScreen splash(":/images/splash.png");
                  splash.show();
                  app.processEvents();
                  QEventLoop loop;
                  QTimer::singleShot(3000, &loop, &QEventLoop::quit);
                  loop.exec();
                  QWidget widget;
                  widget.show();
                  sps.finish(&widget);
                  return app.exec();
                  

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply 28 Apr 2016, 06:14
                  0
                  • S SGaist
                    27 Apr 2016, 19:36

                    This will give you the base to get started:

                    QSplashScreen splash(":/images/splash.png");
                    splash.show();
                    app.processEvents();
                    QEventLoop loop;
                    QTimer::singleShot(3000, &loop, &QEventLoop::quit);
                    loop.exec();
                    QWidget widget;
                    widget.show();
                    sps.finish(&widget);
                    return app.exec();
                    
                    M Offline
                    M Offline
                    M4RZB4Ni
                    wrote on 28 Apr 2016, 06:14 last edited by
                    #9

                    @SGaist
                    Thanks a lot :)

                    Thanks
                    M4RZB4Ni

                    1 Reply Last reply
                    0

                    3/9

                    26 Apr 2016, 08:56

                    topic:navigator.unread, 6
                    • Login

                    • Login or register to search.
                    3 out of 9
                    • First post
                      3/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved