QList<QString> operator<<

890 Views Asked by At

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<<

1

There are 1 best solutions below

1
owang On BEST ANSWER

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) ;
}