title: How to close the qt application when setQuitOnLastWindowClosed(false)
body: <p>I wish to create a project including 3 windows: mainWindow, childWindow1, childWindow2, and only one window should show at a time. And I can switch between these windows.</p>
  
  <p>So I have three tasks:</p>
  
  <ol>
  <li>I place two buttons in the mainWindow and want to use them to make one of the child windows showing and the main window hiding.</li>
  <li>And when I close the child window, I wish to show the main window.</li>
  <li>When I close the main window, terminate the whole application.</li>
  </ol>
  
  <p>I first had a problem:
  If I close the child window, the application exit.
  So I use the qApp.setQuitOnLastWindowClosed(false), and I got task 2 done.
  But another problem occured:
  If I close the main window, the program is still running.</p>
  
  <p>Last problem:
  How to show the child window in the task bar? It looks wired to run a program which can't be found in the taskbar.</p>
  
  <p>I search everywhere I could, any help would be really appreciated!</p>
  
  <p>main.cpp:</p>
  
  <pre><code>int main()
  {
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(false);
    MainWindow mainWindow;
    mainWindow.show();
    return a.exec();
  }
  </code></pre>
  
  <p>mainWindow.cpp:</p>
  
  <pre><code>void mainWindow::button1Clicked()
  {
    this-&gt;hide();
    childWindow1 = new ChildWindow1(this);
    connect(childWindow1, &amp;QMainWindow::destroyed, this, &amp;QMainWindow::show);
    childWindow1-&gt;setWindowModality(Qt::WindowModal);
    childWindow1-&gt;show();
  }
  </code></pre>
  
  <p>childWindow1.cpp</p>
  
  <pre><code>ChildWindow1::ChildWindow1(QWidget *parent)
  : QMainWindow(parent)
  {
    ui.setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose);
  }
  </code></pre>