hello everyone, I've just begun to study qt using qt-creator, I found some tutorials int which the author doesn't use d'tors at all? is it good practice? or it will be better to manage my objects destruction, thanks in advance
Qt has Its own memory management,
Check this
http://stackoverflow.com/questions/2491707/memory-management-in-qt
http://silmor.de/33
BTW It is Qt not QT. Check This
http://ariya.blogspot.com/2009/01/qt-not-qt.html
When a class doesn't declare a destructor, the compiler automatically gives it a definition equivalent to {}
. Often in Qt, this is good enough, even if the class contains pointers. Whenever something derived from QObject
is destroyed, Qt automatically deletes all its children (recursively) as well, as long as each child was passed a "parent" pointer.
If there's anything you think your class's destructor should do, definitely define it yourself.
One other quirk: If the destructor is the only virtual method defined in the class, providing your own non-inline definition can make generation of C++ magic data (vtables) easier on the linker on some systems.
After all the above is considered, whether allowing defaulted destructors is good practice is a matter of opinion. (When I do allow a default destructor, copy constructor, default constructor, and/or assignment operator, I prefer to say that in comments in the public section of the class definition.)