QMapIterator声明几个列表的问题
我有 3 种类型的列表,我正在尝试根据 attribute_type 打印它们。 因此根据 attribute_type 选择迭代器。 问题是,例如,如果 attribute_type == "pis",则执行 if 条件,但完成后它返回到上减法: QMapIterator it(pit.item_parameters),所以这样迭代器无效...... 我应该如何正确申报?
QMapIterator<QString, IP> it(pit.item_parameters);
if (attribute_type == "ips") {
QMapIterator<QString, IP> it(pit.item_parameters);
if (pit.item_parameters.isEmpty()) { return; }
}
else if (attribute_type == "variables") {
QMapIterator<QString, Variable> it(pit.variables);
if (pit.variables.isEmpty()) { return; }
}
else if (attribute_type == "pis") {
QMapIterator<QString, PI> it(pit.pis);
if (pit.pis.isEmpty()) { return; }
}
while(it.hasNext())
{
it.next();
text += it.key();
text += it.value().type;
}
i'm having 3 types of lists, and i'm trying to print them according to attribute_type.
so according attribute_type the iterator is chosen.
the problem is if for example attribute_type == "pis", the if condition is executed but when finished it returns to the upper decleration: QMapIterator it(pit.item_parameters), so this way the iterator is not valid...
how should i declare it properly ?
QMapIterator<QString, IP> it(pit.item_parameters);
if (attribute_type == "ips") {
QMapIterator<QString, IP> it(pit.item_parameters);
if (pit.item_parameters.isEmpty()) { return; }
}
else if (attribute_type == "variables") {
QMapIterator<QString, Variable> it(pit.variables);
if (pit.variables.isEmpty()) { return; }
}
else if (attribute_type == "pis") {
QMapIterator<QString, PI> it(pit.pis);
if (pit.pis.isEmpty()) { return; }
}
while(it.hasNext())
{
it.next();
text += it.key();
text += it.value().type;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的类型
IP
、PI
和Variable
派生自具有type
的同一类ParentClass
> 作为公共成员,你可以这样声明:If your types
IP
,PI
andVariable
derive from the same classParentClass
havingtype
as public member, you can declare it that way: