In Example 8.4, what local stack objects were destroyed when growBunch()
returned?
Notice that Alice does not appear in the dumpObjectTree()
output. When does Alice get destroyed?
Alice does not get destroyed until after the program terminates.
Write your own function,
void showTree(QObject* theparent)
to main.cpp. The output of this function, after all objects have been created, should look like this:
Member: Mike - Parent: A Stack Object Member: Greg - Parent: Mike Member: Peter - Parent: Mike Member: Bobby - Parent: Mike Member: Carol - Parent: A Stack Object Member: Marcia - Parent: Carol Member: Jan - Parent: Carol Member: Cindy - Parent: Carol
Example 8.5. src/iteration/java/showtree.cpp
[ . . . . ] void showTree(QObject* theparent) { QObjectList kids = theparent->children(); QListIterator<QObject*> itr (kids); while (itr.hasNext()) { QObject* ptr = itr.next(); qDebug() << QString("Brady member: %1 - Parent: %2") .arg(ptr->objectName()) .arg(ptr->parent()->objectName()); showTree(ptr); } }
<include src="src/iteration/java/showtree.cpp" href="src/iteration/java/showtree.cpp" role="solution" mode="cpp" segid="showtree"/>
Modify your showTree()
function so that it produces the same output as dumpObjectTree()
.
[ fromfile: children.xml id: None ]
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |