I need a QMainWindow layout to change depending on the number of cores.
Therefore I set it manually (not using the Design mode).

My question is:
After this layout was created, how can I refer to the widgets it contains?

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6.  
  7. //...
  8. buildLayout();
  9. //...
  10.  
  11. // Now I'd like to use something like this:
  12. // ui->threadingTable->...
  13. // However, it's not the member of ui
  14. }
  15.  
  16. void MainWindow::buildLayout()
  17. {
  18. QWidget *window = new QWidget(this);
  19.  
  20. QTableView *threadingTable = new QTableView(window);
  21. //...
  22.  
  23. QGridLayout *layout = new QGridLayout(window);
  24. layout->addWidget(threadingTable, 0, 0);
  25. //...
  26.  
  27. window->setLayout(layout);
  28. this->setCentralWidget(window);
  29. }
To copy to clipboard, switch view to plain text mode 

I can get the QLayoutItem out of this->centralWidget().
Or I can make all widgets in layout members of MainWindow class and access them directly.

However, I feel that neither of these is the right way.
Is there a way to pass the widgets to ui?

So that I could access them by calling
ui->threadingTable