从一个 QStringList 中删除另一个 QStringList 中包含的字符串
我想知道是否有人知道 Qt 库方法可以采用两个 QStringList 并从第二个列表中删除一个列表中包含的所有字符串。
I was wondering if anyone knew of a Qt library method that can take two QStringList
and remove all of the strings contained in one list from the second list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
QList
中没有库函数,也没有 < a href="http://doc.qt.io/qt-5/qstringlist.html" rel="nofollow noreferrer">QStringList
。但你可以编写自己的方法:
There is no library function in
QList
norQStringList
.But you can write your own method:
您可以使用
QList::toSet()
方法并执行一些my_set1.substract(my_set2)
,然后返回QSet::toList()
代码>.但这只是为了玩转转换代码。您最好使用给定的列表自己编写逻辑,它会更快并且不会涉及无用的内存分配(即使是临时的)
You could use the
QList::toSet()
method and do somemy_set1.substract(my_set2)
, and then go backQSet::toList()
.But this is just to play around with conversion code. You'd better code the logic yourself with the given lists, it will be faster and won't involve useless memory allocation (even if temporary)