Question: 1 . Write your own function, void showTree ( Qobject * theparent ) to main.cpp . The output of this function, after all objects have

1. 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
2. Modify your showTree() function so that it produces the same output as dumpobjectTree().```
#include
#include
#include "person.h"
#include
static QTextStream cout(stdout);
//start
void growBunch(){
qDebug() "First we create a bunch of objects." Qt::endl;
QObject bunch;
bunch.setObjectName("A Stack Object"); /* A local stack object - not a pointer
*/
/* other objects are created on the heap */
Person* mike = new Person("Mike", &bunch);
Person* carol = new Person("Carol", &bunch);
new Person("Greg", mike); /* We do not need
to keep pointers to children, because we can
reach them via object navigation. */
new Person("Peter", mike);
new Person("Bobby", mike);
new Person("Marcia", carol);
new Person("Jan", carol);
new Person("Cindy", carol);
new Person("Alice"); /*Alice has no parent - memory leak?*/
qDebug()"
Display the list using QObject::dumpobjectTree()"
& Qt::endl;
bunch.dumpObjectTree(); /* dumpObjectTree() output will appear
on the
screen only if the Qt library has been
compiled with the debugging option turned on.*/
cout "
Ready to return from growBunch()-"
& " Destroy all local stack objects." & Qt::endl;
}
int main(int, char**){
growBunch();
cout & "We have now returned from growBunch()."
&& "
What happened to Alice?" & Qt::endl;
return 0;
}
//end
``````
#include "person.h"
#include
static QTextStream cout(stdout);
Person::Person(QString name, QObject* parent)
: QObject(parent){
setObjectName(name);
cout & QString("Constructing Person: %1").arg(name)
\ll Qt::endl;
}
Person:: Person(){
cout QString("Destroying Person: %1").arg(objectName())
& Qt::endl;
}
``````
#ifndef PERSON_H
#define PERSON_H
#include
#include
//start
class Person : public QObject {
public:
explicit Person(QString name, QObject* parent =0);
virtual ~Person();
};
//end
#endif
```
1 . Write your own function, void showTree (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!