Q:

access layout object Qt 5

I am following this book and it builds some kind of todo GUI app. We firstly create a MainWindow class:
// MainWindow.hpp

#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP

#include <QMainWindow>
#include <QVector>
#include "Task.hpp" // <- irrelevant to my question

namespace Ui {
    class MainWindow;
}

class MainWindow
    : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

public slots:
    void add_task();

private:
    Ui::MainWindow *ui;       // <- this is what I am having problems with
    QVector<Task*> m_tasks_vec;
};

#endif // MAINWINDOW_HPP

In the UI designer we add a couple of widgets and one is called tasks_layout:

Then we go on defining members of MainWindow:
// MainWindow.cpp
#include "MainWindow.hpp"
#include "ui_MainWindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , m_tasks_vec()
{
    ui->setupUi(this);
    connect(ui->add_task_button, &QPushButton::clicked, this, &MainWindow::add_task);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::add_task()
{
    qDebug() << "User clicked on the button!";
    auto default_task_name = "Untitled task";
    auto *task = new Task(default_task_name);
    m_tasks_vec.append(task);
    ui->tasks_layout->addWidget(task); // problem here
}

ui->tasks_layout->addWidget(task); part causes the problem:

no member named 'tasks_layout' in 'Ui::MainWindow'

Looking at the picture above, it seems that tasks_layout maybe nested inside centralWidget, so I thought it might be typo in the book and tried ui->centralWidget->tasks_layout->addWidget(task);, but it didn't fix anything:

no member named 'tasks_layout' in 'QWidget'

What am I doing wrong? 
The closest thing to my question I found is this, and it didn't help me
This is the auto-generated ui_MainWindow.h:
/********************************************************************************
** Form generated from reading UI file 'MainWindow.ui'
**
** Created by: Qt User Interface Compiler version 5.12.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_MainWindow
{
public:
    QWidget *centralWidget;
    QLabel *status_label;
    QPushButton *add_task_button;
    QMenuBar *menuBar;
    QToolBar *mainToolBar;
    QStatusBar *statusBar;

    void setupUi(QMainWindow *MainWindow)
    {
        if (MainWindow->objectName().isEmpty())
            MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
        MainWindow->resize(420, 361);
        centralWidget = new QWidget(MainWindow);
        centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
        status_label = new QLabel(centralWidget);
        status_label->setObjectName(QString::fromUtf8("status_label"));
        status_label->setGeometry(QRect(10, 10, 111, 21));
        add_task_button = new QPushButton(centralWidget);
        add_task_button->setObjectName(QString::fromUtf8("add_task_button"));
        add_task_button->setGeometry(QRect(320, 10, 80, 21));
        MainWindow->setCentralWidget(centralWidget);
        menuBar = new QMenuBar(MainWindow);
        menuBar->setObjectName(QString::fromUtf8("menuBar"));
        menuBar->setGeometry(QRect(0, 0, 420, 20));
        MainWindow->setMenuBar(menuBar);
        mainToolBar = new QToolBar(MainWindow);
        mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
        MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
        statusBar = new QStatusBar(MainWindow);
        statusBar->setObjectName(QString::fromUtf8("statusBar"));
        MainWindow->setStatusBar(statusBar);

        retranslateUi(MainWindow);

        QMetaObject::connectSlotsByName(MainWindow);
    } // setupUi

    void retranslateUi(QMainWindow *MainWindow)
    {
        MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
        status_label->setText(QApplication::translate("MainWindow", "Status: 0 todo / 0 done", nullptr));
        add_task_button->setText(QApplication::translate("MainWindow", "Add task", nullptr));
    } // retranslateUi

};

namespace Ui {
    class MainWindow: public Ui_MainWindow {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_MAINWINDOW_H

A:

Your build system hasn't updated ui_MainWindow.h following changes to MainWindow.ui, it's also lacking the spacers. You need to ensure that it re-runs uic. 
That should be done by QCreator's build action, but if it has gotten confused you may have to clean and/or rebuild.

