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(???);
From the documentation...
That being the case, you should be able to use a
lambda
something along the lines of (untested)...