Hi!
#include<QObject>
#include<QString>
#include<QDebug>
#include<QApplication>
class VerboseObject
: public QObject {
public:
setObjectName(name);
qDebug() << "constructor";
}
~VerboseObject() {
qDebug()<<"Deleted" <<(*this).objectName();
}
void do_sthing() {
qDebug()<<"do sthing" <<(*this).objectName();
}
};
int main(int argc , char* 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;
}
#include<QObject>
#include<QString>
#include<QDebug>
#include<QApplication>
class VerboseObject : public QObject {
public:
VerboseObject(QObject *parent, const QString& name):QObject(parent){
setObjectName(name);
qDebug() << "constructor";
}
~VerboseObject() {
qDebug()<<"Deleted" <<(*this).objectName();
}
void do_sthing() {
qDebug()<<"do sthing" <<(*this).objectName();
}
};
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;
}
To copy to clipboard, switch view to plain text mode
results in:
Starting E:\Develop\QtCentre\ObjectDelete\ObjectDelete\debu g\ObjectDelete.exe... constructor
constructor
constructor
constructor
do sthing "Top"
do sthing "x"
do sthing "y"
do sthing "z"
Deleted "Top"
Deleted "x"
Deleted "y"
Deleted "z"
E:\Develop\QtCentre\ObjectDelete\ObjectDelete\debu g\ObjectDelete.exe exited with code 0
You accidentaly set the objectname of the parent instead of the class itself. And you don't need line breaks. Each call to qDebug() automatically ends with a line break.
Joh
Bookmarks