我在一个类中有一个名为QList的元素,另一个名为k的类对象,我想要做一个深拷贝( this.competence必须是k.competence的一个深拷贝)。我使用迭代器它:
QList< QString>::iterator it;
for( it = k.competence->begin(); it != k.competence->end(); ++it )
{
this.competence << (*it) ;
}我得到了一个错误“不匹配operator<<”。问题是,每当我从循环中尝试这个问题时:
QList< QString>::iterator it;
it = k.competence->begin();
this.competence << *it;它不会产生错误。
编辑:使用QList.append()方法而不是operator<<解析
发布于 2015-02-12 10:07:25
我在这里不了解您的用例,您只需复制QList,就可以完成它的浅拷贝。如果您进一步修改共享实例,将创建一个深度副本。
QList newList(oldList);如果你想按你的方式做,你需要把迭代器附加到你的新列表中。
QList newList;
for(QList< QString>::iterator it = oldList->begin(); it != oldList->end(); it++ )
{
newList.append(*it) ;
}https://stackoverflow.com/questions/28473016
复制相似问题