如何使用qhash :: remove(谓词pred)
qt 6.1引入了方法emove> emove> emovef(predicate pred)
到其许多集合类:qbyTearray
,qhash
,qlist
,qmap
,qmultihhash < /code>,
qmultimap
,qString
和qvarlengthraray
。
但是如何写谓词?
让我们以QHASH
示例:
struct MishMash {
int i;
double d;
QString str;
enum Status { Inactive=0, Starting, Going, Stopping };
Status status;
};
QHash<QString, MishMash> myHash;
// ... fill myHash with key-value pairs
// Now remove elements where myHash[key].status == MishMash::Status::Inactive;
myHash.removeIf(???);
Qt 6.1 introduced the method removeIf(Predicate Pred)
to a number of its collection classes: QByteArray
, QHash
, QList
, QMap
, QMultiHash
, QMultiMap
, QString
and QVarLengthArray
.
But how do I write a predicate?
Let's take a QHash
example:
struct MishMash {
int i;
double d;
QString str;
enum Status { Inactive=0, Starting, Going, Stopping };
Status status;
};
QHash<QString, MishMash> myHash;
// ... fill myHash with key-value pairs
// Now remove elements where myHash[key].status == MishMash::Status::Inactive;
myHash.removeIf(???);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从文档...
在这种情况下,您应该能够使用
lambda
按照(未经测试)...From the documentation...
That being the case, you should be able to use a
lambda
something along the lines of (untested)...