0

I have a QList element named competence inside a class, and another class object named k. I want to make a deep copy( this.competence must be a deep copy of k.competence ). I use an iterator it:

QList< QString>::iterator it;
for(  it = k.competence->begin(); it != k.competence->end(); ++it )
{
    this.competence << (*it) ;
}

I got an error "no match for operator<<". The problem is whenever I try this out of a loop:

QList< QString>::iterator it;
it = k.competence->begin();
this.competence << *it;

it doesn't give errors.

EDIT: RESOLVED using QList.append() method instead of operator<<

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Sorry but this does not make much sense, if competence is an item of the list how can you iterate over an item ? you should iterate over the list in the meantime why you do not take a look at this answer http://stackoverflow.com/questions/16800206/how-to-deep-copy-qmap-and-other-qt-containers – Marco Feb 12 '15 at 08:53
  • Please, always include the exact verbatim error the compiler gives you. – ftynse Feb 12 '15 at 09:25
  • Thanks all guys! You were really helpfull – Luca Nicoletti Feb 12 '15 at 11:52

1 Answers1

1

I dont get your use case here, you can do a shallow copy of a QList just by copying it. If you further modify the shared instance, a deep copy will be created.

QList newList(oldList);

If you want to do it your way, you need to append the iterator to your new list

QList newList;
for(QList< QString>::iterator it = oldList->begin(); it != oldList->end(); it++ )
{
    newList.append(*it) ;
}
owang
  • 48
  • 5