title: Qt: Multiple windows in a parent/child chain, parent does not close children?
body: <p>I am trying to create multiple windows in a chain: window 1 is the parent of window 2, window 2 is the parent of window 3, etc.  When I close one window, I would like all its children to close as well.  Currently, if I close the top level window, all others close, as hoped, but closing, for example, window 2, only closes window 2, not window 3, etc.  How should I be doing this?  Thanks for your help!</p>
  
  <p>main_window.cpp</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
  {
      QPushButton* button = new QPushButton("Open 1", this);
      connect(button, SIGNAL(clicked()), this, SLOT(on_button_clicked()));
  }
  
  void MainWindow::on_button_clicked() {
      window1 *w = new window1(this);
      w-&gt;show();
  }
  </code></pre>
  
  <p>window1.cpp</p>
  
  <pre><code>window1::window1(QWidget *parent) : QWidget(parent)
  {
      this-&gt;setWindowFlags(Qt::Window); // in order to have a free-standing window
  
      QPushButton* button = new QPushButton("Open 2", this);
      connect(button, SIGNAL(clicked()), this, SLOT(on_button_clicked()));
  }
  
  void window1::on_button_clicked() {
      window2 *w = new window2(this);
      w-&gt;show();
  }
  </code></pre>
  
  <p>window2.cpp</p>
  
  <pre><code>window2::window2(QWidget *parent) : QWidget(parent)
  {
      this-&gt;setWindowFlags(Qt::Window);
  
      QLabel* label = new QLabel("Window 2", this);
  }
  </code></pre>