开发者

QMapIterator declaration of several lists problem

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") {
    QMapI开发者_StackOverflow中文版terator<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;

}


If your types IP, PI and Variable derive from the same class ParentClass having type as public member, you can declare it that way:

QMapIterator<QString, ParentClass> it;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜