Hello
Thank you for your help one again. I used std::map and it updates correctly. I have a problem with the routes(source and destination). I sometimes have multiple source address(string) going to different destinations and I read that with std::map() i cannot have multiple keys. The mapping that worked for the links(unique keys and values) is
std
::map< std
::string,
QGraphicsItem * > QgraphicRectItems;
//declared in my .h file
rectangleColor->setData(0, int(pState->m_eState));
QgraphicRectItems.insert(std::make_pair(pState->m_strLinkId, rectangleColor));//make a pair of QGraphicRect items on the scene and their link IDs
std::map< std::string, QGraphicsItem * > QgraphicRectItems;//declared in my .h file
rectangleColor->setData(0, int(pState->m_eState));
QgraphicRectItems.insert(std::make_pair(pState->m_strLinkId, rectangleColor));//make a pair of QGraphicRect items on the scene and their link IDs
To copy to clipboard, switch view to plain text mode
then on my update function i call the mappings like this:
std
::map< std
::string,
QGraphicsItem *>
::iterator it
= QgraphicRectItems.
find(pState
->m_strLinkId
);
if (it != QgraphicRectItems.end()) {
name->setData(0, int(pState->m_eState));
getTitleDescriptionColor(pState, m_backgroundColor, rect);
std::map< std::string, QGraphicsItem *>::iterator it = QgraphicRectItems.find(pState->m_strLinkId);
if (it != QgraphicRectItems.end()) {
QGraphicsItem *name = it->second;
name->setData(0, int(pState->m_eState));
QGraphicsRectItem *rect = qgraphicsitem_cast<QGraphicsRectItem *>(name);
getTitleDescriptionColor(pState, m_backgroundColor, rect);
To copy to clipboard, switch view to plain text mode
But for the routes this doesn't work because sometimes i have multiple keys, so I implemented std::multimap like this:
std
::multimap<std
::string,
QGraphicsItem *> RouteSourceDuplicates;
//declared on my .h file
else if (CORE::checkPtrType<C2DM::RouteState>(_pTitle) == true)
{
C2DM::RouteState *pRoute = (C2DM::RouteState*)_pTitle;
rectangle->setData(0, int(pRoute->m_eTxLinkState));
RouteSourceDuplicates.insert(std::make_pair(pRoute->m_strSource, rectangle));//make a pair of QGraphicRect items on the scene and their source IDs
std::multimap<std::string, QGraphicsItem *> RouteSourceDuplicates;//declared on my .h file
else if (CORE::checkPtrType<C2DM::RouteState>(_pTitle) == true)
{
C2DM::RouteState *pRoute = (C2DM::RouteState*)_pTitle;
rectangle = new QGraphicsRectItem(QRectF(0, 0, 60, 60), text);
rectangle->setData(0, int(pRoute->m_eTxLinkState));
RouteSourceDuplicates.insert(std::make_pair(pRoute->m_strSource, rectangle));//make a pair of QGraphicRect items on the scene and their source IDs
To copy to clipboard, switch view to plain text mode
then on my calling function i did like this:
else if (_eType == QSubscription::UPDATED_TITLES)
{
C2DM::RouteState *pRoute = (C2DM::RouteState*)objPtr->_clone();
for (std
::multimap<std
::string,
QGraphicsItem *>
::iterator Values
= RouteSourceDuplicates.
begin();
Values != RouteSourceDuplicates.end(); ++Values)
{
nameSource->setData(0, int(pRoute->m_eTxLinkState));
QGraphicsRectItem *rectSource
= qgraphicsitem_cast<QGraphicsRectItem
*>
(nameSource
);
//it breaks on this qgraphicitem_cast
getTitleDescriptionColor(pRoute, m_backgroundColor, rectSource);
}
else if (_eType == QSubscription::UPDATED_TITLES)
{
C2DM::RouteState *pRoute = (C2DM::RouteState*)objPtr->_clone();
for (std::multimap<std::string, QGraphicsItem *>::iterator Values = RouteSourceDuplicates.begin();
Values != RouteSourceDuplicates.end(); ++Values)
{
QGraphicsItem *nameSource = Values->second;
nameSource->setData(0, int(pRoute->m_eTxLinkState));
QGraphicsRectItem *rectSource = qgraphicsitem_cast<QGraphicsRectItem *>(nameSource);//it breaks on this qgraphicitem_cast
getTitleDescriptionColor(pRoute, m_backgroundColor, rectSource);
}
To copy to clipboard, switch view to plain text mode
It only works the first time i load the data, second time it just crushes. it gives an Access violation executing location error(please see attachment,it has the error where it breaks). I am struggling to fix it. I am asking for your guidance once again to make it work, please.
the duplicate keys in my data is like this:
pRoute->m_strSource[Node A] pRoute->m_strDestination[Node B] //same source address but different destinations
pRoute->m_strSource[Node A] pRoute->m_strDestination [Node C]
pRoute->m_strSource[Node A] pRoute->m_strDestination[Node B] //same source address but different destinations
pRoute->m_strSource[Node A] pRoute->m_strDestination [Node C]
To copy to clipboard, switch view to plain text mode
and I am using pRoute->m_strSource as my key and QgraphicsItem as a value in std::multimap
Bookmarks