I think you may be confusing several things here --
First off, in this example AddressBook is a subclass of QWidget. This has nothing to do with parent/child relationships (other than the fact that the implementation of AddressBook's constructor needs to be sure to cascade the "parent" pointer to QWidget's constructor). The parent/child relationship and the subclass/superclass relationship are entirely separate and distinct things.
Second, the idiom "(SomeClass* someParameter = 0)" defines an "optional" parameter. That is, the "= 0" means that if you don't code the parameter (ie, in this case just code "AddressBook()" for the constructor) then it's as if you had coded "AddressBook(NULL)", passing a null value for the parent.
Third, the parent-child relationship is used for several things. For all QObjects (not just QWidgets) there's the automatic destruction function. For all QWidgets there's a relationship in terms of how graphics are built and displayed -- children paint on their parents, hiding a parent hides the children, etc. For many parent-child relationsips (mostly between QWidgets) events of certain types (particularly key and touch events) are propagate to the parent if the child doesn't handle them.




Reply With Quote
Bookmarks