You can:
1) pass it by reference:
QMap<int,QList<int> > myMap;
this->myFunction(..other_vars...,myMap);
void myFunction(..other_vars..,QMap<int,QList<int> > & myMap) {
if(!myMap.contains(actor_type))
myMap.insert(actor_type,QList<int>());
if(!myMap[actor_type].contains(actor_id))
myMap[actor_type].append(actor_id);
}
QMap<int,QList<int> > myMap;
this->myFunction(..other_vars...,myMap);
void myFunction(..other_vars..,QMap<int,QList<int> > & myMap) {
if(!myMap.contains(actor_type))
myMap.insert(actor_type,QList<int>());
if(!myMap[actor_type].contains(actor_id))
myMap[actor_type].append(actor_id);
}
To copy to clipboard, switch view to plain text mode
2) de-reference the map before using operator []:
void myFunction(..other_vars..,QMap<int,QList<int> > *myMap) {
if(!myMap->contains(actor_type))
myMap->insert(actor_type,QList<int>());
auto & map = *myMap;
if(!map[actor_type].contains(actor_id))
map[actor_type].append(actor_id);
}
void myFunction(..other_vars..,QMap<int,QList<int> > *myMap) {
if(!myMap->contains(actor_type))
myMap->insert(actor_type,QList<int>());
auto & map = *myMap;
if(!map[actor_type].contains(actor_id))
map[actor_type].append(actor_id);
}
To copy to clipboard, switch view to plain text mode
3) explicit call "operator []" method
void myFunction(..other_vars..,QMap<int,QList<int> > * myMap) {
if(!myMap->contains(actor_type))
myMap->insert(actor_type,QList<int>());
if(!myMap->operator[](actor_type).contains(actor_id))
myMap->operator[](actor_type).append(actor_id);
}
void myFunction(..other_vars..,QMap<int,QList<int> > * myMap) {
if(!myMap->contains(actor_type))
myMap->insert(actor_type,QList<int>());
if(!myMap->operator[](actor_type).contains(actor_id))
myMap->operator[](actor_type).append(actor_id);
}
To copy to clipboard, switch view to plain text mode
myMap[i] in your code is interpreted as indexed access to myMap array (remember the pointers <-> arrays relation), not as calling operator[] method on *myMap object.
Bookmarks