Nominate our 2022 Qt Champions!

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;
        CMainWindow w;
        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;;
        return a.exec();

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

  • Lifetime Qt Champion


    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 you would come across

    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