I'm currently learning the Qt framework and doing my first tutorial. Straight away I saw something that baffled me:
notepad.h
Code:
namespace Ui {
class Notepad;
}
class Notepad : public QMainWindow
{
Q_OBJECT
public:
explicit Notepad(QWidget *parent = 0);
~Notepad();
private:
Ui::Notepad *ui;
};
notepad.cpp
Code:
Notepad::Notepad(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Notepad)
{
ui->setupUi(this);
}
Notepad::~Notepad()
{
delete ui;
}
Note the ui pointer and the heap allocation in the class constructor; I can't wrap my head around why one would do this. What's going on here?