The first way :

MyWindow *wnd = new MyWindow(this); wnd->show(); 

The second way :

 MyWindow wnd(this); wnd.show(); wnd.exec(); 

Why do we need exec() in the second method?

    1 answer 1

    The difference between show() and exec() is that with show() main thread continues to run, and with exec() execution of the main program is suspended until the child window is closed. It is used, for example, in modal dialogs.

    Apparently, in the code from which you took the second example, the child window does something that the main window needs. Therefore, the main thread waits for the child window to close.