Results 1 to 5 of 5

Thread: QMap in QList | i can get value but i can`t set value

  1. #1
    Join Date
    Jan 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMap in QList | i can get value but i can`t set value

    Hi
    i dynamicly create a QMap and put it on QList
    Qt Code:
    1. QMap<QPoint, int> myMap;
    2.  
    3. for(int i=0; i<5; i++)
    4. {
    5. for(int j=0; j<5; j++)
    6. {
    7. myMap.insert(QPoint(j, i), 0);
    8. }
    9. }
    10.  
    11. this->MapList.insert(0, myMap);
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. 1) this->MapList.at(0)[QPoint(x,y)] = 1;
    2.  
    3. 2) this->MapList.at(0).insert(QPoint(x,y), 1);
    To copy to clipboard, switch view to plain text mode 

    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 ?
    Sorry for my English :P

  2. #2
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap in QList | i can get value but i can`t set value

    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.

  3. #3
    Join Date
    Jan 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap in QList | i can get value but i can`t set value

    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
    Qt Code:
    1. this->MapVector[Index].insert(QPoint(x,y), someIndex);
    To copy to clipboard, switch view to plain text mode 
    Last edited by petrusPL; 19th March 2013 at 22:29.
    Sorry for my English :P

  4. #4
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap in QList | i can get value but i can`t set value

    You can do it with QList too
    Qt Code:
    1. this->MapList[0].insert (QPoint (x, y), 1);
    To copy to clipboard, switch view to plain text mode 
    or even
    Qt Code:
    1. this->MapList[0][QPoint(x,y)] = 1;
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMap in QList | i can get value but i can`t set value

    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.

Similar Threads

  1. Containers with derived classes? (QMap or QList)
    By CSmith in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2012, 17:42
  2. QMap QList
    By dare5421 in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2011, 23:17
  3. How to view data stored in Qmap or QList
    By sankar in forum Newbie
    Replies: 6
    Last Post: 17th February 2011, 09:30
  4. QMap in QList ?
    By npc in forum Newbie
    Replies: 2
    Last Post: 5th February 2007, 11:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.