Skip to content

Commit 033be80

Browse files
bacali95nickygerritsen
authored andcommitted
add groups size check
1 parent d9d31ce commit 033be80

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

team.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ Team::Team(QJsonObject team, QHash<QString, Group *> groups, QObject *parent) :
1212
this->name = team.value("name").toString("UNKNOWN");
1313
this->affilation = team.value("affilation").toString("UNKNOWN");
1414
this->nationality = team.value("nationality").toString("UNKNOWN");
15+
this->group = nullptr;
1516
QJsonArray groups_ids = team.value("group_ids").toArray();
16-
QString groupId = groups_ids[0].toString();
17-
if (groups.contains(groupId)) {
18-
this->group = groups[groupId];
19-
this->group->addTeam(this);
20-
} else {
21-
this->group = nullptr;
17+
if (groups_ids.size() > 0){
18+
QString groupId = groups_ids[0].toString();
19+
if (groups.contains(groupId)) {
20+
this->group = groups[groupId];
21+
this->group->addTeam(this);
22+
}
2223
}
2324
}
2425

@@ -48,7 +49,7 @@ QString Team::toString() {
4849
s += " name = " + this->name + "\n";
4950
s += " affilation = " + this->affilation + "\n";
5051
s += " nationality = " + this->nationality + "\n";
51-
s += " group = " + this->group->getId() + " (" + this->group->getName() + ")\n";
52+
s += " group = " + (this->group ? this->group->getId() + " (" + this->group->getName() + ")\n" : "NONE\n");
5253
return s;
5354
}
5455
}

0 commit comments

Comments
 (0)