2010-07-26 2 views
0

3 가지 유형의 목록이 있는데 attribute_type에 따라 인쇄하려고합니다. 따라서 attribute_type에 따라 반복기가 선택됩니다. 예를 들어 attribute_type == "pis"인 경우 if 조건이 실행되었지만 완료되면 상위 Decleration으로 돌아갑니다. QMapIterator it (pit.item_parameters),이 방법은 반복자가 유효하지 않습니다 ... how 내가 제대로 선언해야합니까?여러 목록의 QMapIterator 선언에 문제가 있습니다.

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; 

} 

답변

0

당신의 유형 IP, PIVariable 공공 회원으로 type을 갖는 동일한 클래스 ParentClass에서 파생 경우에, 당신은 그런 식으로 선언 할 수

QMapIterator<QString, ParentClass> it; 
관련 문제