I need to check if a QSet contains a certain value and if it is not there, I want to insert it and return a boolean value indicating whether the value was inserted (true) or whether it had already been there (false). My question is how to do this efficiently. The following code actually calculates the hash and searches the set two times. This is very inefficient.
QSet<QString> names;
bool inserted = false;
QString name = "Dave";
if (!names.contains(name))
{
inserted = true;
names.insert(name);
}