I've recently returned to C++ after a break of a few years and would like a few points clarifying about new and delete, as used in class constructors / destructors.

I understand that every single thing created using new, must be explicitly deleted before the program quits. Correct?

Following Qt's built in Address Book tutorials (as sadly all the tuxradar ones fail with segmentation faults) I note that even though the class constructor in question uses new to create dynamic objects, the destructor is left empty. Ok, that might be down to stripping down the code for the purposes of education but when I add delete commands to the destructor for each instance of new in the constructor, I run into trouble. See the annotations in the code.

if that doesn't do it post so and i'll have fiddle but i learned it as [] , but you have to free all memory you use for every constructor you must have a de-constructor,
i was using this as reference but someone who is better than me might know different ?or if you could post the rest of the code? hth paul

Yes, because 'nameLabel' only exists within the scope of the constructor (between the braces ). The example doesn't feature 'nameLabel' though, are you adding it yourself? However, one thing to note here is that the 'ui' object has 'ownership' of these objects when they're constructed; it's counter-intuitive in a way but because 'ui' is deleted by the constructor, it will clean up the remaining objects for you

spaceyhase - thank you! That makes sense now. I'm not adding 'nameLabel' myself, it appears in the version of the tutorial that's built into Qt Creator's help. I think that this is the same version here too.

Not quite sure what you mean about the 'ui' object though, do you mean the QWidget class that the AddressBook class is derived from? And quite what is it cleaning up automatically?

We construct a new AddressBook widget on the stack and invoke its show() function to display it. However, the widget will not be shown until the application's event loop is started. We start the event loop by calling the application's exec() function; the result returned by this function is used as the return value from the main() function. At this point, it becomes apparent why we instanciated AddressBook on the stack: It will now go out of scope. Therefore, AddressBook and all its child widgets will be deleted, thus preventing memory leaks.

That's the last part of Part 1 - Does that help..

PS. thanks for the link to 4.6 - I.ve got 4.5 install and only the first 4 part of this tutorial are there.