You might have noted that although we created a number of objects in the constructor using the new operator, we didn't destroy those objects anywhere (for example, in the destructor). This is because of the way the memory is managed by Qt. Qt doesn't do any garbage collecting (as C# or Java does), but it has this nice feature related to QObject parent–child hierarchies. The rule is that whenever a QObject instance is destroyed, it also deletes all of its children. This is another reason to set parents to the objects that we create—if we do this, we don't have to care about explicitly freeing any memory.
Since all layouts and widgets inside our top-level widget (an instance of MainWindow class) are its direct ...