Results 1 to 2 of 2

Thread: QMap issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QMap issue

    Hello forum,

    I am trying to implement a graph data-structure using QMap<QString,int> and QVector<Node*> .

    QMap<> contains the node name and index of the QVector so that i can accesss the Node* directly.

    And i have the following function to retrieve the index for the vector to retrieve the node


    //////////////////////////////////////////////////////////////////////////

    Qt Code:
    1. int SceneHierarchy::getNodeIndex(const QString &nodeName) const
    2. {
    3. int pos = -1;
    4. //find the node in the map with the key - node name
    5. QMap<QString,int>::const_iterator iter = m_nodeMap.constFind(nodeName);
    6.  
    7. if(iter == m_nodeMap.constEnd())
    8. {
    9. //node name is not found in the map
    10. pos = -1;
    11. }
    12. else
    13. {
    14. //!node found inside the map and so we
    15. //!return the index of the node in the vector list
    16. pos = iter.value();
    17. }
    18. return pos;
    19. }
    To copy to clipboard, switch view to plain text mode 

    ////////////////////////////////////////////////////////////////////////////


    The program crashes at the following line

    Qt Code:
    1. QMap<QString,int>::const_iterator iter = m_nodeMap.constFind(nodeName);
    To copy to clipboard, switch view to plain text mode 

    I do not get what could be the possible problem with the above code. If the name is not found it will simply returns constEnd(), right?

    I must be missing something. Anyone in the forum help to point it out?


    Thanks
    Sajjad

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMap issue

    I can't see an error right now. Is m_nodeMap set up correctly? Nevertheless I would use QMap::value()
    Qt Code:
    1. return m_nodeMap.value(nodeName, -1);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QMap Issue
    By ManuMies in forum Qt Programming
    Replies: 4
    Last Post: 11th November 2010, 00:08
  2. QMap
    By AnithaRagupathy in forum Qt Programming
    Replies: 5
    Last Post: 23rd November 2007, 13:26
  3. Qmap
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 23rd November 2007, 10:43
  4. [solved] Qmap and pointer issue
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 26th September 2007, 14:34
  5. Reg - QMap(Qt3.3.4)
    By suresh in forum Newbie
    Replies: 3
    Last Post: 18th October 2006, 22:04

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
  •  
Qt is a trademark of The Qt Company.