I have a problem with the Qt foreach function. I have a Phrase class, which is a subclass of QList. In ~ Phrase, I delete all GlossItem pointers.
In an iteration using GlossItem pointers in a phrase, I would like to use Qt foreach:
For some reason, foreach is doing a deep copy on Phrase (I know this because I needed to implement a copy constructor). But if there is a copy of the phrase - and if I do not want to create a deep copy of each GlossItem, it means that these pointers will be deleted twice. (Or deleted once, and then worked.) So I have to use this, which works, but is less beautiful.
for(int i=0; i<phrase->count(); i++ ) { GlossItem *glossItem = phrase->at(i);
Is there a way around this or do I just need to live with it?
source share