namus
25th June 2010, 13:57
#include<QObject>
#include<QString>
#include<QDebug>
#include<QApplication>
class VerboseObject : public QObject {
public:
VerboseObject(QObject *parent, const QString& name):QObject(parent){
parent->setObjectName(name);
qDebug()<<"\n constructor \n";
}
~VerboseObject() {
qDebug()<<"\n Deleted"<<(*this).objectName()<<"\n";
}
void do_sthing() {
qDebug()<<"\n do sthing"<<(*this).objectName()<<"\n";
}
};
int main(int argc , char* argv[])
{
QApplication A(argc ,argv);
VerboseObject top(&A,"Top");
VerboseObject *x = new VerboseObject(&top,"x");
VerboseObject *y = new VerboseObject(&top,"y");
VerboseObject *z = new VerboseObject(&top,"z");
top.do_sthing();
x->do_sthing();
y->do_sthing();
z->do_sthing();
return 0;
}
I am expecting output:
constructor
constructor
constructor
constructor
do sthing "Top"
do sthing "x"
do sthing "y"
do sthing "z"
Deleted "Top"
Deleted "x"
Deleted "y"
Deleted "z"
#include<QString>
#include<QDebug>
#include<QApplication>
class VerboseObject : public QObject {
public:
VerboseObject(QObject *parent, const QString& name):QObject(parent){
parent->setObjectName(name);
qDebug()<<"\n constructor \n";
}
~VerboseObject() {
qDebug()<<"\n Deleted"<<(*this).objectName()<<"\n";
}
void do_sthing() {
qDebug()<<"\n do sthing"<<(*this).objectName()<<"\n";
}
};
int main(int argc , char* argv[])
{
QApplication A(argc ,argv);
VerboseObject top(&A,"Top");
VerboseObject *x = new VerboseObject(&top,"x");
VerboseObject *y = new VerboseObject(&top,"y");
VerboseObject *z = new VerboseObject(&top,"z");
top.do_sthing();
x->do_sthing();
y->do_sthing();
z->do_sthing();
return 0;
}
I am expecting output:
constructor
constructor
constructor
constructor
do sthing "Top"
do sthing "x"
do sthing "y"
do sthing "z"
Deleted "Top"
Deleted "x"
Deleted "y"
Deleted "z"