I have a QVariantMap
, which is an alias for QMap<QString, QVariant>
. And I have a function which takes QStringView key
as argument. I want to search a value in the map by the key.
QVariantMap map;
QStringView key;
QVariant v = map.value(key);
But the third line does not compile. Of course I could convert the string view to QString
but this means one extra memory allocation. Is there any way around this which avoids the unnecessary allocation? How to lookup the value by just the string view?
there is no other solution,
QVariant v = map.value(key.toString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.