Question: 1 . Write your own function, void showTree ( Qobject * theparent ) to main.cpp . The output of this function, after all objects have
Write your own function,
void showTreeQobject 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
Modify your showTree function so that it produces the same output as dumpobjectTree
#include
#include
#include "person.h
#include
static QTextStream coutstdout;
start
void growBunch
qDebug "First we create a bunch of objects." Qt::endl;
QObject bunch;
bunch.setObjectNameA Stack Object"; A local stack object not a pointer
other objects are created on the heap
Person mike new PersonMike &bunch;
Person carol new PersonCarol &bunch;
new PersonGreg mike; We do not need
to keep pointers to children, because we can
reach them via object navigation.
new PersonPeter mike;
new PersonBobby mike;
new PersonMarcia carol;
new PersonJan carol;
new PersonCindy carol;
new PersonAlice; 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 mainint char
growBunch;
cout & We have now returned from growBunch
&&
What happened to Alice?" & Qt::endl;
return ;
end
#include "person.h
#include
static QTextStream coutstdout;
Person::PersonQString name, QObject parent
: QObjectparent
setObjectNamename;
cout & QStringConstructing Person: argname
ll Qt::endl;
Person:: Person
cout QStringDestroying Person: argobjectName
& Qt::endl;
#ifndef PERSONH
#define PERSONH
#include
#include
start
class Person : public QObject
public:
explicit PersonQString name, QObject parent ;
virtual ~Person;
;
end
#endif
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
