views:

10

answers:

1

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;

}
A: 

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;
gregseth