When I use things like:
file.h
file.cpp
Do I have to do this in the .cpp file (e.g. in the destructor):Qt Code:
To copy to clipboard, switch view to plain text mode
Or isn't this needed when using Qt/Qt functions/Qt classes?
When I use things like:
file.h
file.cpp
Do I have to do this in the .cpp file (e.g. in the destructor):Qt Code:
To copy to clipboard, switch view to plain text mode
Or isn't this needed when using Qt/Qt functions/Qt classes?
Last edited by Voldemort; 2nd May 2007 at 20:45.
Using Qt version 4.3.0
Qt doesn't offer any magical all-covering garbage collection but a QObject deletes its children. For more information see:
J-P Nurmi
1) I use 2 classes, these are 2 Widgets (inheritance), there are all Qt classes (like QAction, QPushButton, ...) in the functions, will they be delete automatically?
2) But what when I don't inheritance QObject or QWidget between an other class, will I have to delete all the others (like QAction, QPushButton)?
Using Qt version 4.3.0
1. If you create your classes with a parent that is not created by you explicitly, but by qt ( a main window, etc ), then your objs will be deleted automatically by their parent.
But if your objs are parentless, besides the fact that layouts and other things won't work properly, you'll have to delete them manually.
2. Manually, of course ( unless you have some object manager that takes care of them - disposes them as soon as no none uses them anymore ).
Regards
1) So you mean when my class does not inheritance QObject or QWidget I have to delete them manually?
2) Can I delete all objects (parent or parentless) without problems (QObject complaining?)? Then I won't make any mistakes .
Using Qt version 4.3.0
1. Yes. Is that so hard to do? Isn't c/c++ all about this? This is a great thing! More control, more flexibility... . Of course, you can choose not to delete any objects , but then everyone who uses your app will need a lot of memory.
2. Yes, you can delete them , but be sure to make them NULL right after you delete them.
Regards
I'll only use delete when the class doesn't inheritance QWidget or QObject. Then everything should be ok.
@marcel: That's the reason why I program in C++, I like the control an flexibility and C++ is one of the fastest languages.
Using Qt version 4.3.0
Very well then
Regards
Bookmarks