使用Q遍历QMap [英] Iterating over a QMap with for
本文介绍了使用Q遍历QMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个QMap
对象,我正在尝试将其内容写入文件.
I've a QMap
object and I am trying to write its content to a file.
QMap<QString, QString> extensions;
//..
for(auto e : extensions)
{
fout << e.first << "," << e.second << '\n';
}
为什么会得到:error: 'class QString' has no member named 'first' nor 'second'
e
不是QPair
类型吗?
推荐答案
如果要使用first
和second
的STL样式,请执行以下操作:
If you want the STL style with first
and second
, do this:
for(auto e : extensions.toStdMap())
{
fout << e.first << "," << e.second << '\n';
}
如果您想使用Qt提供的功能,请执行以下操作:
If you want to use what Qt offers, do this:
for(auto e : extensions.keys())
{
fout << e << "," << extensions.value(e) << '\n';
}
这篇关于使用Q遍历QMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文