Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I show an other widget or dialog before mainwindow



  • Hi
    I want to show a loading dialog before mainwindow in main.cpp.

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        PreparingForm form;
        form.exec();
    
        CMainWindow w;
        w.Init();
        w.FunctionsInit();
        w.show();
    
        return a.exec();
    }
    

    but it doesn't work



  • @Mihan
    If PreparingForm is derived from QDialog then so far as I am aware the code you show should indeed show it before the main window. If not you could just test:

        QApplication a(argc, argv);
    
        PreparingForm form;
        form.show();
    
        return a.exec();
    

    Otherwise Google for qt show dialog before main window, there are many posts.


  • Lifetime Qt Champion

    Hi,

    What exactly does not work ?

    The code you show does this:

    • show a dialog while blocking the execution since you called exec.
    • once the dialog is closed, it will continue and show your main window.


  • Thanks @JonB @SGaist

    I want to show a loading window, when initializing the main window, the loading window will receive the signals about steps and show corresponding text. After initializing, the loading window will be closed and the main window will be showed.

    Now I'm confused that the loading window is showed only with frame after I change exec() to show(), seems that the window doesn't update().



  • @Mihan
    Then that is called a modeless window, and you would search for: qt show modeless dialog before main window.

    From say https://stackoverflow.com/questions/49339411/qt-non-modal-dialog-before-main-window-is-created you would come across https://doc.qt.io/qt-5/qsplashscreen.html:

    A splash screen is a widget that is usually displayed when an application is being started. Splash screens are often used for applications that have long start up times (e.g. database or networking applications that take time to establish connections) to provide the user with feedback that the application is loading.



  • Thank you @JonB

    QSplashScreen is exactly what I need ! ! !


Log in to reply