title: SIGSEGV when adding widget in Qt
body: <p>I implemented example (chapter 2) from "Mastering Qt 5" book but the code crashes when adding widget to centralWidget's layout:</p>
  
  <pre><code>ui-&gt;centralWidget-&gt;layout()-&gt;addWidget(&amp;mCpuWidget)
  </code></pre>
  
  <p>I suspect that the centralWidget does not have layout, hence it crashes but I don't know how to fix that?</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow),
  mCpuWidget(this)
  {
      ui-&gt;setupUi(this);
      SysInfo::instance().init();
      ui-&gt;centralWidget-&gt;layout()-&gt;addWidget(&amp;mCpuWidget);
  
  }
  </code></pre>
  
  <p>Here are two more classes which might help figure out the problem. Some of you might have the book too with all of the code (hence I mentioned it).</p>
  
  <pre><code>CpuWidget::CpuWidget(QWidget* parent):
  SysInfoWidget(parent),
  mSeries (new QPieSeries (this))
  {
      mSeries-&gt;setHoleSize(0.35);
      mSeries-&gt;append("CPU Load", 30.0);
      mSeries-&gt;append("CPU Free", 70.0);
  
      QChart* chart = chartView().chart();
      chart-&gt;addSeries(mSeries);
      chart-&gt;setTitle("CPU Average Load");
  }
  </code></pre>
  
  <p>This class creates and sets layout (QVBoxLayout)</p>
  
  <pre><code>    SysInfoWidget::SysInfoWidget(QWidget *parent, int startDelayMs, int updateSeriesDelayMs) :
      QWidget(parent),
      mChartView(this)
  
  {
      mRefreshTimer.setInterval(updateSeriesDelayMs);
      connect(&amp;mRefreshTimer, &amp;QTimer::timeout,
              this, &amp;SysInfoWidget::updateSeries);
  
      QTimer::singleShot(startDelayMs,
                         [this] {mRefreshTimer.start();});
  
      mChartView.setRenderHint(QPainter::Antialiasing);
      mChartView.chart()-&gt;legend()-&gt;setVisible(false);
  
      QVBoxLayout* layout = new QVBoxLayout(this);
      layout-&gt;addWidget(&amp;mChartView);
      setLayout(layout);
  }
  </code></pre>