You don't have to declare anything.
public:
QLabel *lab
= new QLabel(this);
// current object (this) is set as the parent) lab->setText("TEST");
}
};
int main(int argc, char **argv){
MyWidget wgt;
wgt.show();
return app.exec();
}
class MyWidget : public QWidget {
public:
MyWidget(QWidget *parent =0 ) : QWidget(parent){
QLabel *lab = new QLabel(this); // current object (this) is set as the parent)
lab->setText("TEST");
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
MyWidget wgt;
wgt.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
When "wgt" is destroyed so are all its child QObjects (the label being one of them). No memory leak and no pointers declared (and no dangling pointers).
Bookmarks