There is no magic. Simply put, QObject automatically removes its children in its destructor. So, as long as your widget has a parent and that you are destroying that parent, you do not need to worry about children. So, if you were wondering what the QObject * parent parameter is, well, what is it for.
Also from the doc doc:
All child objects are deleted. If any of these objects is on the stack or globally, sooner or later your program will crash.
So, avoid giving parents objects that are stacked.
Etienne de martel
source share