Splash Screen not working in Qt Widget Desktop Application



  • Hi There,

    I am trying make a simple splash screen which will show up for a few seconds but when i execute the code,
    Splash Screen appears together with the main window :(
    Below is the code i am using:

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

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QSplashScreen *splash=new QSplashScreen;
    splash->setPixmap(QPixmap("/home/vijayzang/Downloads/ECM_Logo.png"));
    splash->show();
    
    
    
    QTimer::singleShot(2500,splash,SLOT(close()));
    //QTimer::singleShot(2500,&w,SLOT(close()));
    
    MainWindow w;
    
    w.show();
    
    return a.exec(&#41;;
    

    }
    @

    [edit: added missing coding @ tags SGaist]



  • So what is your problem ???


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are calling both show one after the other so the windows will be shown one after the other.

    If you really want to only show MainWindow after a delay you can try something like:

    @
    QSplashScreen splash;
    splash.setPixmap(QPixmap("/home/vijayzang/Downloads/ECM_Logo.png"));
    splash.show();
    MainWindow w;

    QTimer::singleShot(2500,&splash,SLOT(hide()));
    QTimer::singleShot(2500,&w,SLOT(show()));
    return a.exec();
    @

    No pointer needed in this case, otherwise you have a memory leak.



  • Thanks for your prompt reply...Will make the changes and check it.

    Cheers :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.