trandatnh
trandatnh

Reputation: 351

Use QMap or Qlist container if I want to search a name in a list of names

I want to maintain a list of Names and then search if the literal "a name" exists in the list.

Should I use a QMap:

QMap<QString, bool> Names;
Names.find("a name");

Or a QList:

QList<QString> Names:
bool found = false;
foreach(QString name, Names){
    if (name == "a name"){
        found = true;
        break;
    }
}

Upvotes: 0

Views: 467

Answers (2)

spiritwolfform
spiritwolfform

Reputation: 2293

What you may want to use is QSet
You can search whether a name is in the Names by calling contains() method

Upvotes: 2

peppe
peppe

Reputation: 22826

If you don't need the container to have any order, use a QSet<QString>.

Upvotes: 3

Related Questions