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. QSplashScreen Example not working
Qt 6.11 is out! See what's new in the release blog

QSplashScreen Example not working

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 11.7k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    I am trying to implement a slash screen by editing my main file and adding some of the Qt4 example code.

    this is what I have:
    @
    #include <QtGui/QApplication>
    #include <QSplashScreen>
    #include <QThread>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    // create application instance
    QApplication a(argc, argv);

    // set up splash screen
    QPixmap pixmap("splash.jpg");
    QSplashScreen *splash = new QSplashScreen(pixmap);
    splash->showMessage("Loading...");
    
    // show splash screen
    splash->show();
    
    // sleep for 3 seconds
    sleep(3);
    
    // show main window
    MainWindow w;
    w.show();
    
    // remove splash screen
    splash->finish(&MainWindow);
    delete splash;
    
    return a.exec&#40;&#41;;
    

    }
    @

    Now for some reason I am getting and error on the splash->finish(&MainWindow); line stating its expecting a primary expression before the line. This confuses me because splash is the main pointer. This is directly from the Qt Documentation as well.

    Any Ideas?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      @
      splash->finish(&w);
      @

      MainWindow is a type, w a variable of that type. Please consider learning C++ basics before using Qt...

      (Also: do not delete your splash screen before hiding it. Just create it on the stack, or find a way to deleteLater() it when it's closed).

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rahul Das
        wrote on last edited by
        #3

        Not related though, in the above code, sleep() is working ?


        Declaration of (Platform) independence.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Das
          wrote on last edited by
          #4

          I haven't tried though, made a couple of small changes. Might work.

          @#include <QtGui/QApplication>
          #include <QSplashScreen>
          #include <QThread>
          #include "mainwindow.h"

          class I : public QThread
          {
          public:
          static void sleep(unsigned long secs) {
          QThread::sleep(secs);
          }
          };

          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv);
          QPixmap pixmap("splash.jpg");
          QSplashScreen *splash = new QSplashScreen(pixmap);
          splash->showMessage("Loading...");
          splash->show();

          I::sleep(3);
          
          MainWindow w;
          w.show();
          splash->finish(&w);
          
          return a.exec&#40;&#41;;
          

          }@


          Declaration of (Platform) independence.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on last edited by
            #5

            http://developer.qt.nokia.com/wiki/Threads_Events_QObjects#92dd35cc61ffc41d02defdcef071856d

            Please.

            Software Engineer
            KDAB (UK) Ltd., a KDAB Group company

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rahul Das
              wrote on last edited by
              #6

              [quote author="peppe" date="1313187434"]http://developer.qt.nokia.com/wiki/Threads_Events_QObjects#92dd35cc61ffc41d02defdcef071856d

              Please.[/quote]

              Thank you Peppe, But,am still curious, how would i use QTimer in the above lines of codes?
              I failed to do :(


              Declaration of (Platform) independence.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                In the above code, it won't help, as you wanted the sleep before the mainwindow pops up.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loladiro
                  wrote on last edited by
                  #8

                  What about
                  @
                  int main(int argc, char *argv[])
                  {
                  QApplication a(argc, argv);
                  QPixmap pixmap("splash.jpg");
                  QSplashScreen *splash = new QSplashScreen(pixmap);
                  splash->showMessage("Loading...");
                  splash->show();

                  MainWindow w;
                  splash->finish(&w);
                  
                  QTimer t;
                  t.setInterval(3000);
                  t.setSingleShot(true);
                  connect(&t,SIGNAL(timeout()),&w,SLOT(show()));
                  connect(&t,SINGAL(timeout()),splash,SLOT(close()));
                  t.start();
                  
                  return a.exec(&#41;;
                  

                  }
                  @
                  EDIT: Nevermind, I had a wrong conception of finish() worked. I updated the code. It should work now.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Rahul Das
                    wrote on last edited by
                    #9

                    bq. I updated the code. It should work now.

                    Thanks alot loladiro, will try with this.


                    Declaration of (Platform) independence.

                    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