title: How to show a window in Qt and deleting it as soon as it's closed?
body: <p>As a very simple example, I want to show a dialog in Qt when I press a button. The usual pattern for this (in the application I'm currently working on) seems to be as follows:</p>
  
  <pre><code>class MainWindow {
    ...
  private slots:
    buttonClicked();
    ...
  private:
    ChildWindow * childWindow;
  }
  
  MainWindow::MainWindow(QWidget * parent) : QWidget(parent) {
    ...
    childWindow = new ChildWindow(this);
    ...
  }
  
  MainWindow::buttonClicked() {
    childWindow.show();
  }
  </code></pre>
  
  <p>Coming from .NET and Windows Forms (and because I don't need access to that object from elsewhere in the class) the following pattern is more familiar to me:</p>
  
  <pre><code>button1_Clicked(object sender, EventArgs e) {
    ChildWindow f = new ChildWindow();
    f.Show();
  }
  </code></pre>
  
  <p>The local variable means I don't have yet another instance field and also that the window won't linger around in memory for much longer than necessary. A direct translation of that to C++ would be a bit ugly because no one would clear up afterwards. I tried the following things:</p>
  
  <ol>
  <li><p><code>shared_ptr</code>. No luck, the window is <code>delete</code>d as soon as the method ends which means the new window appears for a split second and vanishes again. Not so good.</p></li>
  <li><p><code>exec()</code> instead of <code>show()</code>. This would work for modal dialogs, but documentation seemed to imply that it also stops the event loop and that you should call <code>QApplication::processEvents()</code> regularly if it still needs to be updated. I understand little enough here but I guess it's not too nice either.</p></li>
  <li><p><code>deleteLater()</code>. Sadly, just showing a window doesn't block <code>deleteLater</code> so it vanishes as soon as it appears.</p></li>
  </ol>
  
  <p>Is there a nice option to just clean up after the window when I close it?</p>