QT - 只用键填充 QMap,然后为每个键添加值
QT - Fill a QMap with only key, and then add values for each key
我想知道是否可以只用键填充一个QMap,然后为每个键添加值。
例如:
QMap<QString, QString> map;
map.insert("key", null (??));
感谢您的回答
好吧,您可以用空字符串值填充它,然后只需更改字符串即可:
QMap<QString, QString> map;
map.insert("key", "");
// and later
map[key] = "something else";
不可能只用键填充映射,但是您可以用空字符串作为值来初始化它。
请注意,在 Qt 中,空字符串和空字符串是有区别的。
因此我会将地图的每个元素初始化为
map.insert("key", QString()); // map of null strings
相对于
map.insert("key", ""); // map of empty strings
我想知道是否可以只用键填充一个QMap,然后为每个键添加值。
例如:
QMap<QString, QString> map;
map.insert("key", null (??));
感谢您的回答
好吧,您可以用空字符串值填充它,然后只需更改字符串即可:
QMap<QString, QString> map;
map.insert("key", "");
// and later
map[key] = "something else";
不可能只用键填充映射,但是您可以用空字符串作为值来初始化它。
请注意,在 Qt 中,空字符串和空字符串是有区别的。
因此我会将地图的每个元素初始化为
map.insert("key", QString()); // map of null strings
相对于
map.insert("key", ""); // map of empty strings