Do I have to delete objects from the heap in the example below? And if yes, how?
#include
#include
#include
Instead of managing the memory manually, you can let the compiler do it for you. At that point you may ask: why use the heap at all? You should keep things by value as much as feasible, and let the compiler do the hard work.
The objects will be destroyed in the reverse order of declaration. Thus the splitter - the implicit parent - must be declared first, so that it doesn't attempt to incorrectly delete its children. In C++, the order of declarations has a meaning!
int main(int argc, char* argv[])
{
QApplication app(argc,argv);
QSplitter splitter;
QTreeView tree;
QListView list;
QTableView table;
splitter.addWidget(&tree);
splitter.addWidget(&list);
splitter.addWidget(&table);
splitter.show();
return app.exec();
}