Thanks marcel,
Actually mWidget is a pointer on the widget.
Assigning it to NULL doesn't change a thing.
another example :
This works :
ZeTextWidget * textWidget = new ZeTextWidget("Salut");
layout->addWidget(textWidget);
delete layout;
delete textWidget;
ZeTextWidget * textWidget = new ZeTextWidget("Salut");
QHBoxLayout * layout = new QHBoxLayout();
layout->addWidget(textWidget);
delete layout;
delete textWidget;
To copy to clipboard, switch view to plain text mode
This one crashes :
ZeTextWidget textWidget("Salut");
layout->addWidget(&textWidget);
delete layout;
ZeTextWidget textWidget("Salut");
QHBoxLayout * layout = new QHBoxLayout();
layout->addWidget(&textWidget);
delete layout;
To copy to clipboard, switch view to plain text mode
Thos two pieces of code are all the same for me.
- In one case :
- I'm declaring a self allowed variable in local
- Assigning it to the layout.
- Deleting the layout
- the self allowed variable is/should be deleted at the end of the function locally.
- In another case :
- I'm declaring a pointer variable
- Allocating it myself.
- Assigning it to the layout.
- Deleting the layout
- Deleting the pointer manually.
Imho the result is/should be exactly the same.
Bookmarks