Thanks everybody,
Well well,
The problem was coming from my side :
this :
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
and this :
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
Perfectly works.
When deleted, a layout doesn't delete the assigned objects.
Concerning the setting the pointer to NULL :
As marcel said, this doesn't work :
void deletePtr(int* x)
{
delete x;
x = NULL;.
}
int main(void)
{
int varAllocatedOnStack = 5;
deletePtr(&varAllocatedOnStack);
}
void deletePtr(int* x)
{
delete x;
x = NULL;.
}
int main(void)
{
int varAllocatedOnStack = 5;
deletePtr(&varAllocatedOnStack);
}
To copy to clipboard, switch view to plain text mode
But I'm more doing something like that :
void deletePtr(int* x)
{
delete x;
}
int main(void)
{
int * newVar = new int(5);
int * newPtr = newVar;
(...)
newPtr = NULL;.
deletePtr(varAllocatedOnStack);
}
void deletePtr(int* x)
{
delete x;
}
int main(void)
{
int * newVar = new int(5);
int * newPtr = newVar;
(...)
newPtr = NULL;.
deletePtr(varAllocatedOnStack);
}
To copy to clipboard, switch view to plain text mode
As iw2nhl said setting a pointer to NULL is a valid code.
Setting a pointer to NULL is a way knowing if a pointer has been assigned to something or not.
And correct me if I'm wrong but the heap will never create a 0 pointer variable.
Setting a pointer to NULL is like saying : okay the adress of my pointer isn't valid anymore.
And I don't see why it would crash anything in my case, and it doesn't.
Bookmarks