How does QSpacerItem get deleted?
-
So, I know usually objects get deleted in Qt when their parents gets deleted. What about
QSpacerItem
, for example?
Since it is not possible to set its parent, how does it get deleted if I writespacerItem = new QSpacerItem(10, 10);
in a
.cpp
file, wherespacerItem
is declared in a.h
file? Do I have to take care of deletions by myself? -
-
@kshegunov Thank you very much, I missed that on the docs :)
Now all makes sense, thank you again. -
@alogim
As an additional note:
If you wish to delete an item that's been held by a layout, you should detach it first by using QLayout::takeAt. Then the ownership of the item will no longer belong to the layout, so you can safely delete it. You should take care not to delete the item if it's handled by a layout.Kind regards.
-
Hi,
To add to @kshegunov, if you don't use
spacerItem
in any layout (very unlikely but still) then it's your job to delete it. -
@kshegunov Err… I somehow managed to misread that last statement :D