Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I show an other widget or dialog before mainwindow
Forum Update on Monday, May 27th 2025

How can I show an other widget or dialog before mainwindow

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MihanM Offline
    MihanM Offline
    Mihan
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • MihanM Mihan

      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

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • MihanM Offline
          MihanM Offline
          Mihan
          wrote on last edited by Mihan
          #4

          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().

          JonBJ 1 Reply Last reply
          0
          • MihanM Mihan

            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().

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @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.

            MihanM 1 Reply Last reply
            2
            • JonBJ JonB

              @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.

              MihanM Offline
              MihanM Offline
              Mihan
              wrote on last edited by
              #6

              Thank you @JonB

              QSplashScreen is exactly what I need ! ! !

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved