Results 1 to 20 of 20

Thread: display QSplashScreen

  1. #1
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default display QSplashScreen

    At the startup of a Qt program, I want to display a QSplashScreen. Maybe it's too fast to get the image. But how can i make the image to last for 2 seconds.
    I'm a greenhand, Thanks!

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: display QSplashScreen

    Hi,
    maybe you can connect a QTimerto a splashscreen slot. But in general you should be happy that your app starts so fast

  3. #3
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by janus View Post
    Hi,
    maybe you can connect a QTimerto a splashscreen slot. But in general you should be happy that your app starts so fast
    I had looked up the documentation, but i failed to make it. Can you give me an example? Thanks

  4. #4
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: display QSplashScreen

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. splash->setPixmap(QPixmap(":/images/splash.png"));
    6. splash->show();
    7.  
    8. MyApp mainwindow;
    9.  
    10. QTimer::singleShot(2500, splash, SLOT(close()));
    11. QTimer::singleShot(2500, &mainwindow, SLOT(show()));
    12.  
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Thanks for your reply.

    But the main problem is that I can't see the image. Even I can make it to delay 2s, but the startup picture didn't turn up.

    What's the problem? Can anyone help? Thanks

  6. #6
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: display QSplashScreen

    Hi,

    hard to guess without code

  7. #7
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by HelloDan View Post
    Thanks for your reply.

    But the main problem is that I can't see the image. Even I can make it to delay 2s, but the startup picture didn't turn up.

    What's the problem? Can anyone help? Thanks
    did you set up a qrc file?

  8. #8
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by GioFX View Post
    did you set up a qrc file?
    Thanks for your advice.

    Qt Code:
    1. #include <QApplication>
    2. #include <QSplashScreen>
    3. //#include <QThread>
    4. //#include<QTimer>
    5. #include<ctime>
    6. #include "mainwindow.h"
    7. /*
    8. class SleeperThread : public QThread
    9. {
    10. public:
    11. static void msleep(unsigned long msecs)
    12. {
    13. QThread::msleep(msecs);
    14. }
    15. };
    16. */
    17.  
    18. int main(int argc, char *argv[])
    19. {
    20. QApplication app(argc, argv);
    21.  
    22.  
    23. splash->setPixmap(QPixmap(":/images/splash.png"));
    24. splash->show();
    25.  
    26. //splash->showMessage( "Initializing..." );
    27. // app.processEvents();
    28. //......................
    29. MainWindow mainWin;
    30.  
    31. splash->showMessage( "Creating Widgets Page..." );
    32. app.processEvents();
    33.  
    34. splash->showMessage( "Creating Database Page..." );
    35. app.processEvents();
    36.  
    37. splash->showMessage( "Creating Games Page..." );
    38. app.processEvents();
    39.  
    40. // SleeperThread::msleep(2000);
    41.  
    42. time_t t;
    43. t = time(NULL);
    44.  
    45.  
    46. //QTimer::singleShot(2500, splash, SLOT(close()));
    47. //QTimer::singleShot(2500, &mainWin, SLOT(show()));
    48.  
    49.  
    50.  
    51. mainWin.show();
    52.  
    53. while( difftime(time(NULL),t) < 5.0 ) { }
    54.  
    55.  
    56. splash->finish(&mainWin);
    57. delete splash;
    58.  
    59. return app.exec();
    60. }
    To copy to clipboard, switch view to plain text mode 

    This time, I changed my code and alse set up my qrc file. But the program just show a left top rectangle area of the program instead of the image. How can i make image show?
    I will appreciate any reply. Thanks

  9. #9
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: display QSplashScreen

    Hi,

    did you add qrc file to the project file and does it have the correct path prefix?

  10. #10
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by janus View Post
    Hi,

    did you add qrc file to the project file and does it have the correct path prefix?
    Thanks! In fact I had done all the things. But I found that the following code did make shown the startup images. But the image under the program, So I can't see the startup image. Thanks


    Qt Code:
    1. #include <QApplication>
    2. #include<QTimer>
    3. #include <QSplashScreen>
    4. #include "mainwindow.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. splash->setPixmap(QPixmap(":/images/splash.png"));
    11. splash->show();
    12.  
    13.  
    14.  
    15. MainWindow mainWin;
    16.  
    17. QTimer::singleShot(2500, splash, SLOT(close()));
    18. QTimer::singleShot(2500, &mainWin, SLOT(show()));
    19.  
    20.  
    21. mainWin.show();
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: display QSplashScreen

    You shouldnt be calling mainWin.show() since it will show after timer times out.

    Still you can have the following sequence too -
    Qt Code:
    1. mainWin.show();
    2. splash.show();
    3. QTimer::singleShot(2500, splash, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    Hope it works

  12. #12
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: display QSplashScreen

    i dont think mainWin should be shown before the splashscreen..after all, the primary reason of using a splashscreen is to show smth until the main window will show..thus, just removing the mainWin.show should work..also u can have a bit of delay in closing the splash and showing the mainWin..so, if i were u, i'd write

    Qt Code:
    1. MainWindow mainWin;
    2.  
    3. QTimer::singleShot(2500, splash, SLOT(close()));
    4. QTimer::singleShot(2600, &mainWin, SLOT(show()));
    To copy to clipboard, switch view to plain text mode 

  13. The following user says thank you to talk2amulya for this useful post:

    HelloDan (12th February 2009)

  14. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: display QSplashScreen

    By the way, QSplashScreen hides automatically when you click on it. There's no need to delay showing of the main window when the splash screen was clicked away, right?
    J-P Nurmi

  15. The following user says thank you to jpn for this useful post:

    HelloDan (12th February 2009)

  16. #14
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by jpn View Post
    By the way, QSplashScreen hides automatically when you click on it. There's no need to delay showing of the main window when the splash screen was clicked away, right?
    Thanks. Indeed. I tried it

  17. #15
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by aamer4yu View Post
    You shouldnt be calling mainWin.show() since it will show after timer times out.

    Still you can have the following sequence too -
    Qt Code:
    1. mainWin.show();
    2. splash.show();
    3. QTimer::singleShot(2500, splash, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    Hope it works
    Thanks. But I just want the splash to show up before the app

  18. #16
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by talk2amulya View Post
    i dont think mainWin should be shown before the splashscreen..after all, the primary reason of using a splashscreen is to show smth until the main window will show..thus, just removing the mainWin.show should work..also u can have a bit of delay in closing the splash and showing the mainWin..so, if i were u, i'd write

    Qt Code:
    1. MainWindow mainWin;
    2.  
    3. QTimer::singleShot(2500, splash, SLOT(close()));
    4. QTimer::singleShot(2600, &mainWin, SLOT(show()));
    To copy to clipboard, switch view to plain text mode 
    Thanks!
    But it doesn,t works. the main program will still cover the startup image.

    It's that any methods?

  19. #17
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: display QSplashScreen

    hanks. But I just want the splash to show up before the app
    I said u need call mainWindow.show(); u were going to show main window after timer times out.
    Also in above post, did u call splash.show() ?
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. splash->setPixmap(QPixmap(":/images/splash.png"));
    6. splash->show();
    7.  
    8. MainWindow mainWin;
    9.  
    10. QTimer::singleShot(2500, splash, SLOT(close()));
    11. QTimer::singleShot(2500, &mainWin, SLOT(show()));
    12.  
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

  20. The following user says thank you to aamer4yu for this useful post:

    HelloDan (13th February 2009)

  21. #18
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: display QSplashScreen

    ok, this code is working

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "qtnetwork.h"
    3. #include<QTimer>
    4. #include <QSplashScreen>
    5. #include <QMainWindow>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. splash->setPixmap(QPixmap("C:\\Documents and Settings\\am002bh\\Desktop\\error-checkin.PNG"));
    12. splash->show();
    13.  
    14. QMainWindow mainWin;
    15.  
    16. QTimer::singleShot(2500, splash, SLOT(close()));
    17. QTimer::singleShot(2500, &mainWin, SLOT(show()));
    18.  
    19. return a.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    i have used QMainWindow and instead of using a qrc, i have used a straight path..so either u have a problem with ur qrc or mainwindow itself

  22. The following user says thank you to talk2amulya for this useful post:

    HelloDan (13th February 2009)

  23. #19
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display QSplashScreen

    Thanks all of you.

    I made a mistake. There are two winMain.show();

    QTimer::singleShot(2500, splash, SLOT(close()));
    QTimer::singleShot(2500, &mainWin, SLOT(show()));


    mainWin.show();

  24. #20
    Join Date
    Apr 2010
    Posts
    23
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: display QSplashScreen

    Quote Originally Posted by HelloDan View Post
    Thanks all of you.

    I made a mistake. There are two winMain.show();

    QTimer::singleShot(2500, splash, SLOT(close()));
    QTimer::singleShot(2500, &mainWin, SLOT(show()));


    mainWin.show();
    could you please post the complete working code?
    also r u working on on Which OS r u working?

    Thanks

Similar Threads

  1. OS/X how to get physical display handle
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2009, 19:51
  2. phonon on a "secondary" display (X11)
    By mnavarro in forum Qt Programming
    Replies: 10
    Last Post: 21st November 2008, 16:38
  3. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 21:55
  4. QSplashScreen Weirdness
    By mclark in forum Qt Programming
    Replies: 11
    Last Post: 19th November 2007, 06:49
  5. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08

Tags for this Thread

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.