PDA

View Full Version : QMap in QList | i can get value but i can`t set value



petrusPL
19th March 2013, 22:14
Hi
i dynamicly create a QMap and put it on QList

QMap<QPoint, int> myMap;

for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
myMap.insert(QPoint(j, i), 0);
}
}

this->MapList.insert(0, myMap);

and i can get the value but i can`t set it :C



1) this->MapList.at(0)[QPoint(x,y)] = 1;

2) this->MapList.at(0).insert(QPoint(x,y), 1);



1) lvalue required as left operand of assignment

2)passing 'const QMap<QPoint, int>' as 'this' argument of 'QMap<Key, T>::iterator QMap<Key, T>::insert(const Key&, const T&) [with Key = QPoint; T = int]' discards qualifiers [-fpermissive]

why it dont work :( ?

jesse_mark
19th March 2013, 22:47
1) this->MapList.at(0)[QPoint(x,y)] = 1;
what this line suppose to do ??


2) this->MapList.at(0).insert(QPoint(x,y), 1);
you cannot insert because you are using ( at (index)), this method is used to retrieve value only, not to insert or edit.

petrusPL
19th March 2013, 23:29
1)line suppose to insert value 1 to QPoint(x,y) key in QMap :(

:(((((
i was thinking that this->MapList.at(0) give me my QMap and i can do anything with this :CCCC
so there is a some trick to instert data to QMap in QList :(((( ?
please help

Added after 23 minutes:

Ok sorry for spam :(
I do this with QVector :)

this->MapVector[Index].insert(QPoint(x,y), someIndex);

lanz
20th March 2013, 06:32
You can do it with QList too

this->MapList[0].insert (QPoint (x, y), 1);
or even

this->MapList[0][QPoint(x,y)] = 1;

jesse_mark
20th March 2013, 19:40
As Lanz said, you can use [ ] for insertion, but not .at(), use "at" when you want to retrieve data as it very fast. but u can not use it for insertion.