Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: Splash Screen

  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Splash Screen

    Hi. I've got a question. In C++ GUI Programming with Qt 4 is explained how to do a splash screen, but it's different than this, what I wanna do. In book it was explained how to do this when you were implementing forms manually, and I was doing forms by designer. And I want to display splash screen without for example "loading plugins", but only and image, which is displaying for 4 seconds, and after it main window is shown. How can I do that, on my main.cpp file:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlastiqueStyle>
    3. #include "maker.h"
    4. #include "about.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication::setStyle ( new QPlastiqueStyle() );
    9. QApplication app(argc, argv);
    10. MainWindow MainWindow;
    11. MainWindow.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Splash Screen

    Create the splashscreen, show it, start a timer and when it timeouts, close it. Take a look at QSplashScreen docs to see some examples.

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    But the examples in docs doesn't say how to set timer

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Splash Screen

    Because they are not meant to close after 4 seconds Try reading the docs of a class that has a "timer" word in its name...

  5. #5
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    Quote Originally Posted by wysota View Post
    Because they are not meant to close after 4 seconds Try reading the docs of a class that has a "timer" word in its name...
    I mean to close not application, but spalsh. I've done everything what's described in docs (without timer, yet)
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlastiqueStyle>
    3. #include <QSplashScreen>
    4. #include "maker.h"
    5. #include "about.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication::setStyle ( new QPlastiqueStyle() );
    10. QApplication app(argc, argv);
    11. QPixmap pixmap("new/prefix1/Poker.jpg");
    12. QSplashScreen splash(pixmap);
    13. splash.show();
    14. app.processEvents();
    15.  
    16. MainWindow MainWindow;
    17. MainWindow.show();
    18. splash.finish(&MainWindow);
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    But when I run the program, splash screen doesn't appear. Regards

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Maybe you have a problem with the jpeg plugin. I have seen a few people getting this problem. Try using a PNG image instead.

    As for the timer, do something like this in main after you create the splash:
    Qt Code:
    1. QTimer splashTimer();
    2. splashTimer.setSingleShot( true );
    3. splashTimer.setInterval( 4000 ); //4 seconds
    4. connect( &splashTimer, SIGNAL( timeOut() ), &splash, SLOT( close() );
    5. splashTimer.start();
    To copy to clipboard, switch view to plain text mode 

    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Splash Screen

    Because you close it immediately. Splash screen is usually meant to occupy user's attention when the application takes time to initialize itself. If you only want to show the splashscreen because of eye candy, show the splash, start the timer and close it when the timer timeouts.

  8. #8
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    Marcel - i use jpg images for actions, and I works correctly.
    [B][/WysotaB] - yes, I want to use it as "eye candy". What do you mean that I close the app immediatly? Splash screen is waiting for my answer, isn't it?

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Understood.

    QSpkashScreen::finish:
    Makes the splash screen wait until the widget mainWin is displayed before calling close() on itself.
    This doesn't necessarily mean that you have time to see the splash.
    The main window may become visible very quickly, depending on what it contains, what initialization code you have and on the performance of your computer.

    Use the timer to make it stay visible for a predefined period of time.

    Regards

  10. #10
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    I've done this:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlastiqueStyle>
    3. #include <QSplashScreen>
    4. #include "maker.h"
    5. #include "about.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication::setStyle ( new QPlastiqueStyle() );
    10. QApplication app(argc, argv);
    11. QPixmap pixmap("new/prefix1/Poker.jpg");
    12. QSplashScreen splash(pixmap);
    13.  
    14.  
    15. QTimer splashTimer();
    16.  
    17. splashTimer.setSingleShot( true );
    18.  
    19. splashTimer.setInterval( 4000 ); //4 seconds
    20.  
    21. connect( &splashTimer, SIGNAL( timeOut() ), &splash, SLOT( close() );
    22. splashTimer.start();
    23. splash.show();
    24.  
    25. MainWindow MainWindow;
    26. MainWindow.show();
    27. splash.finish(&MainWindow);
    28. return app.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 
    As you told me, but there appear errors:
    http://allyoucanupload.webshots.com/...25593906661174
    What's wrong with this code? It should show splash screen for 4 seconds, and after this time if should start application, right?

  11. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Make sure you include <QTimer>.
    Also remove splash.finish() because now the splash closes when the timer time outs.

    The behavior is not as you describe it.
    The splash will stay visible for 4 seconds but in the mean time the main window may become visible. The splash does not block the main window.

    Regards

  12. #12
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    The bahavior is exactly the same what I want it to be. I included QTimer, but errors are still the same:
    http://allyoucanupload.webshots.com/...25593906661174
    Regards

  13. #13
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    You declared splashTimer as:
    Qt Code:
    1. QTimer splashTimer();
    To copy to clipboard, switch view to plain text mode 
    Drop the (), because it may be the problem.

    Also, you can select and copy the output from the console and paste it in your reply.
    Just select the text, right-click and select Copy.
    It is kind of boring to follow all that links to see the screen.

    EDIT: that really is the problem. I think you're using gcc. The MS compiler thinks it is a function when declared like that.

    Regards

  14. #14
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    You did this mistake, though I deleted it, and added QObject:: prefix to connect. And I have a question. Why it's
    Qt Code:
    1. &splashTimer
    To copy to clipboard, switch view to plain text mode 
    ? What about "&" ?
    Application compiled well, but when I launch the program, it doesn't display splash screen. Why? Regards

  15. #15
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Oh, I did a mistake...Shame on me then.
    You could have used the QApplication instance to access connect.

    The "&" is there because connect takes a pointers to QObjects as parameters.
    Both splash and splashTimer are allocated on the stack, therefore you must pass their address to connect.

    I don't know why it does not show...
    Have you removed splash.finish()?

    Regards

  16. #16
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    But without QObject:: prefict is shows error, that connect is undeclared... But I still don't know, why it doesn't show splash screen.
    Regards

  17. #17
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    It is OK that you use QObject::connect.
    I meant that you could have also used app.connect(...).

    But make sure you don't call splash.finish() anymore.

  18. #18
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    Yes, I don't call splash.finish(). I deleted it from my main.cpp. So what's the problem with? Regards

  19. #19
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Are you sure 100% that the image path is correct and the image is loaded OK?
    If so, then check if the splash is displayed behind the main window...

  20. #20
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    I checked it, splash isn't displayed behind mw. No, I'm not 100% sure. How can I make myself sure? I've got resource file, and location of it new/prefix1/Poker.jpg. But I saw in book, that after quotation mark and before first letter is ":", so
    "new/prefix1/Poker.jpg"
    would be
    ":new/prefix1/Poker.jpg"
    Is that making things different?

Similar Threads

  1. Problem with Splash Screen ?
    By vinod in forum Qt Programming
    Replies: 13
    Last Post: 11th April 2020, 18:15
  2. multi screen
    By Thomas Feldman in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2007, 17:41
  3. QTimer based Splash Screen
    By bpetty in forum Newbie
    Replies: 6
    Last Post: 15th December 2006, 01:51
  4. Replies: 3
    Last Post: 8th December 2006, 19:51
  5. Problem with screen update...
    By mysearch05 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2006, 19:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.