I stumbled upon this in the documentation for QMainWindow::setMenuBar(QMenuBar * menuBar):
Note: QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.
Example code (in a method of a class deriving from QMainWindow):
QMenuBar * menuBar = new QMenuBar(this);
setMenuBar(menuBar) // <-- immediately transfer ownership
// use menuBar pointer to add actions, menus, and what not
Can I still rely on my local pointer to my QMenuBar after a call to setMenuBar? I mean, is it completely guaranteed?
When I delete my QMainWindow derived class, the QMenuBar object is also deleted because the QMainWindow is set as its parent when constructing it - but what policy lies in the later "ownership takeover" through setMenuBar other than a copy of reference/pointer?