title: Qt creating MDI document window
body: <p>I am trying to create a MDI document program. I have a question on creating the subwindow.</p>
  
  <p>This is my mainwindow constructor:</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      setWindowTitle(tr("MDI"));
  
      workspace = new QMdiArea;
      setCentralWidget(workspace);
      //fileNew();
  
      createActions();
      createMenus();
      createToolbars();
  
      statusBar()-&gt;showMessage(tr("Done"));
  
      enableActions();
  }
  </code></pre>
  
  <p>The interesting point is the <code>fileNew();</code> function. It is a private slot function actually which I want to invoke when "New File" button is triggered. Here is the private slot <code>fileNew()</code> function:</p>
  
  <pre><code>void MainWindow::fileNew()
  {
      DocumentWindows* document = new DocumentWindows;
      workspace-&gt;addSubWindow(document);
  }
  </code></pre>
  
  <p>This function works perfectly when I call from the mainwindow constructor. However, there is a problem when I call it from the <code>createActions();</code> function which uses a signal-slot mechanism.</p>
  
  <p>Here is my <code>createActions()</code></p>
  
  <pre><code>void MainWindow::createActions()
  {
      newAction = new QAction(QIcon(":/Image/NewFile.png"),tr("&amp;New"),this);
      newAction-&gt;setShortcut(tr("Ctrl+N"));
      newAction-&gt;setToolTip(tr("Open new document"));
      connect(newAction, SIGNAL(triggered(bool)), this, SLOT(fileNew()));
  }
  </code></pre>
  
  <p>No subwindow is created even the SLOT is triggered. Subsequently, I find out that if I add <code>document-&gt;show();</code>, everything works well.</p>
  
  <pre><code>void MainWindow::fileNew()
  {
      DocumentWindows* document = new DocumentWindows;
      workspace-&gt;addSubWindow(document);
      document-&gt;show();
  }
  </code></pre>
  
  <p>My question is: Why the <code>show()</code> function is needed in a SLOT but not in the constructor?</p>
  
  <p>PS. <code>DocumentWindows</code> is just a class inherits <code>QTextEdit</code>.</p>