Inheritance and handling memory mangement automaticly[Solved]
-
hi,
i created a class that inherits QWidget,but
the only reason i'm inherting QWidget is
because i want to handel memory automaticly
"destruction part" by the main class which is
QMainWindow ,even though i don't need any
of the QWidget feautures or functions
so should i use this method or just use delete
in the destructor of the class and delete the pointers
or maybe i got it all wrong? -
Hi,
If your class is not a GUI widget, then you should definitely not inherit QWidget. You can inherit QObject instead; read "this":http://qt-project.org/doc/qt-5.1/qtcore/objecttrees.html for more details on QObject memory management.
However, if you don't need QObject's features like signal-slot communications, a better solution is to use a smart pointer like "QSharedPointer":http://qt-project.org/doc/qt-5.1/qtcore/qsharedpointer.html -- read "this":http://stackoverflow.com/questions/106508/what-is-a-smart-pointer-and-when-should-i-use-one for info on when/how to use smart pointers
-
thanks ,exactly what i was looking for