能正常运行for-loop程序片段:
for(auto item : m_image_disp_view->m_drawROI->getRoiRect())
{
if(item.second.color == QColorConstants::Svg::magenta)
{
QRect rect = item.second.rect;
mappedRect = transform.mapRect(rect);
have_magenta_ROI = true;
break;
}
}
用std::find_if优化后的程序片段,程序能正常编译,但是运行的时候就报错崩溃了:
auto it = std::find_if(m_image_disp_view->m_drawROI->getRoiRect().begin(),
m_image_disp_view->m_drawROI->getRoiRect().end(),
[](const auto& item) {
return item.second.color == QColorConstants::Svg::magenta;
});
if (it != m_image_disp_view->m_drawROI->getRoiRect().end())
{
QRect rect = it->second.rect;
mappedRect = transform.mapRect(rect);
have_magenta_ROI = true;
LOG(INFO)<<"After have_magenta_ROI = true";
}
else
{
LOG(INFO)<<"There is no ROI selection!";
}
上述代码中m_image_disp_view->m_drawROI->getRoiRect()的数据类型为:
std::map<int, ROI_INFO_STRUCT>
ROI_INFO_STRUCT的定义如下:
typedef struct{
QRect rect;
QColor color;
}ROI_INFO_STRUCT;
自己看了半天没看出哪里有问题,问了几个AI,都觉得没问题,很奇怪,各位帮忙看看,谢谢。
--
FROM 210.72.70.*