Qt closeevent and garbage collection
Hi, is it necessary to call delete when a qt application is closed? For example I created several widgets.
Are they automatically deleted when the closeEvent is executed?
or is it necessary to call the destructor everytime the app is closed?
Also, is there any effect in memory allocation when either of these forms are used?
QWidget myWidget;
QWidget *myWidget = new QWidget();
Re: Qt closeevent and garbage collection
QWidget internally having a garbage collector .so no need to destruct as the base widget will automatically clean its child and child's children recursivly ..
if u feel uncomfortable of not setting any widget as a parent to the base widget use QSharedPointer to declare that widget ..
Re: Qt closeevent and garbage collection
Quote:
Originally Posted by
ehnuh
Are they automatically deleted when the closeEvent is executed?
No, closing a widget does not delete it. You can still query its members or even show it again.
Since top-level widgets usually do not have parents assigned, you need to delete them yourself if you want them gone.
Re: Qt closeevent and garbage collection
or use Qt::WA_DeleteOnClose
Re: Qt closeevent and garbage collection
the delete applies when creating the object using the new keyword. so if I declare my widget to be, QWidget BasicWidget.....this would automatically be deleted once I close my application?
Re: Qt closeevent and garbage collection
Quote:
Originally Posted by
ehnuh
the delete applies when creating the object using the new keyword. so if I declare my widget to be, QWidget BasicWidget.....this would automatically be deleted once I close my application?
All memory is freed when you close your application, regardless how the object is created. It only matters if a destuctor of an object is called or not.