iAmoric
iAmoric

Reputation: 1967

QT - Fill a QMap with only key, and then add values for each key

I would like to know if is it possible to fill a QMap with only key, and then for each key add value.

for example, something like :

QMap<QString, QString> map;
map.insert("key", null (??));

Thanks for your answer

Upvotes: 2

Views: 5992

Answers (2)

Emerald Weapon
Emerald Weapon

Reputation: 2540

Filling a map with only keys is not possible, however you can initialize it with null strings as values.

Note that in Qt there is a distinction between empty strings and null strings.

I would therefore initialize each element of the map as

map.insert("key", QString()); // map of null strings

as opposed to

map.insert("key", ""); // map of empty strings

Upvotes: 3

dtech
dtech

Reputation: 49289

Well, you can fill it with empty string values, then simply change the strings:

QMap<QString, QString> map;
map.insert("key", "");

// and later

map[key] = "something else";

Upvotes: 3

Related Questions