title: How to change window title and central widget in Qt?
body: <p>Hi, I have a problem with changing window title and central widget in Qt. 
  There is MainWindow:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class MainWindow : public QMainWindow
    {
  // (...)
    QStackedWidget* widgets;
    Quiz* widget1, *widget2;
    }
  </code></pre>
  
  <p>and there is a class Quiz:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class Quiz : public QWidget
    {
    public slots:
      void myClicked();
    }
  </code></pre>
  
  <p>I wanted to change MainWindow title after clicking on button, which is a element of Quiz (and it is connected with slot myClicked).</p>
  
  <pre class="lang-cpp prettyprint-override"><code>void Quiz::myClicked()
   {
   static_cast&lt;MainWindow&gt;(parent).myFunction();
   }
  
  void MainWindow::myFunction()
  {
  widget2 = new Quiz(this,2);
  widgets-&gt;addWidget(widget2);
  std::cout&lt;&lt;"current wdgt: " &lt;&lt; widgets-&gt;currentIndex() &lt;&lt; std::endl; // shows: 0
  widgets-&gt;setCurrentWidget(widget2);
  std::cout&lt;&lt;"current wdgt " &lt;&lt; widgets-&gt;currentIndex() &lt;&lt; std::endl; // shows: 1
  
  setWindowTitle("newTitle");
  std::cout&lt;&lt;"Title is " &lt;&lt; windowTitle().toStdString() &lt;&lt; std::endl;
  
  }
  </code></pre>
  
  <p>So widgets->currentIndex shows index of new widget but nothing is changed in my window. The same problem is with window title - method windowTitle() returns new title, but title on a titlebar is old. Why? 
  If I change title in Quiz::myClicked by:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>parent-&gt;setWindowTitle("newTitle");
  </code></pre>
  
  <p>it works! Why it works how strange? Please help. </p>