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;
}
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;
}
To copy to clipboard, switch view to plain text mode
////////////////////////////////////////////////////////////////////////////
The program crashes at the following line
QMap<QString,int>::const_iterator iter = m_nodeMap.constFind(nodeName);
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
Bookmarks