title: qt creator how to get layout from main window?
body: <p>I am trying to dynamically add QTableViews to a mainwindow when a button is pressed.</p>
  
  <p>It looks like the widget class has a member layout and I can set it.</p>
  
  <p><strong>qwidget.h:</strong></p>
  
  <pre><code>public:
      QLayout *layout() const;
      void setLayout(QLayout *);
  </code></pre>
  
  <p><strong>main:</strong></p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      QGridLayout *layout = new QGridLayout();
      MainWindow w;
      w.setLayout( layout );
      w.show();
  
  
      return a.exec();
  }
  </code></pre>
  
  <p><strong>part of mainwindow.cpp:</strong></p>
  
  <pre><code>void MainWindow::on_btn_main_run_clicked()
  {
  
      this-&gt;Run();
  
  }
  
  void MainWindow::Run() {
  
      this-&gt;up_dr_ = std::make_unique&lt;DataReader&gt;(
          DataReader( "C:/CPP/Simulator/log_file.txt" )
      );
      up_dr_-&gt;ReadFile();
      up_dr_-&gt;PrintLines();
  
      TableModel model( this );
      QTableView table_view;
      table_view.setModel( &amp;model );
  
      // this line below there does not work. It throws the error left of add widget must point to class/...
      this-&gt;layout-&gt;addWidget( &amp;table_view );
  
      table_view.show();
  
  }
  </code></pre>
  
  <p>I can't get the layout member from the mainwindow to attach the qtableview, so when I run it the view just briefly pops up as its own window.</p>
  
  <p>I am new to c++ and qt, so there may be something I am doing fundamentally wrong. Is this the right way to get the layout and attach it and if so what is my mistake here? If not, how should I tackle this?</p>