[Qt-interest] QMap container issue
Sajjad
dosto.walla at gmail.com
Sat Jul 23 15:05:07 CEST 2011
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
//////////////////////////////////////////////////////////////////////////
int SceneHierarchy::getNodeIndex(const QString &nodeName) const
{
int pos = -1;
//find the node in the map with the key - node name
QMap<QString,int>::const_iterator iter = m_nodeMap.constFind(nodeName);
if(iter == m_nodeMap.constEnd())
{
//node name is not found in the map
pos = -1;
}
else
{
//!node found inside the map and so we
//!return the index of the node in the vector list
pos = iter.value();
}
return pos;
}
////////////////////////////////////////////////////////////////////////////
The program crashes at the following line
QMap<QString,int>::const_iterator iter = m_nodeMap.constFind(nodeName);
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110723/01f3fa8c/attachment.html
More information about the Qt-interest-old
mailing list