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

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.
  • M4RZB4NiM Offline
    M4RZB4NiM Offline
    M4RZB4Ni
    wrote on 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

    xeggsyX 1 Reply Last reply
    0
    • RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on 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
      • M4RZB4NiM M4RZB4Ni

        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();
        }
        
        xeggsyX Offline
        xeggsyX Offline
        xeggsy
        wrote on 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.

        M4RZB4NiM 1 Reply Last reply
        1
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on 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
          • xeggsyX xeggsy

            @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.

            M4RZB4NiM Offline
            M4RZB4NiM Offline
            M4RZB4Ni
            wrote on 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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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

              M4RZB4NiM 1 Reply Last reply
              0
              • SGaistS SGaist

                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 ?

                M4RZB4NiM Offline
                M4RZB4NiM Offline
                M4RZB4Ni
                wrote on 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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

                  M4RZB4NiM 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    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();
                    
                    M4RZB4NiM Offline
                    M4RZB4NiM Offline
                    M4RZB4Ni
                    wrote on last edited by
                    #9

                    @SGaist
                    Thanks a lot :)

                    Thanks
                    M4RZB4Ni

                    1 Reply Last reply
                    0

                    • Login

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