c++ - 崩溃 : this may be due to a corruption of the heap

标签 c++ qgis qwt

我在我的插件中使用 qwt5 和 qgis 2.8.1((32 位版本),它使用 qwt6)。当我运行我的 C++ 程序时,它崩溃并出现此错误:

enter image description here

问题出现在这个函数中(在debug中运行):

//delete all the items attached to QwtPlot
const QwtPlotItemList &list = m_pPlot->itemList ();
qDeleteAll(list.begin(), list.end());

我将此函数替换为:

QwtPlotItemIterator it = list.begin();
while ( it != list.end() )
{
  QwtPlotItem *item = *it;
  ++it; // increment before removing item from the list
  item->attach(NULL);
  delete item;
}

但在这条指令中再次发生同样的崩溃:

delete item;

请问,您对这个问题有什么想法吗?

最佳答案

来自 Qwt User's Guide

A QwtPlotItemList of all attached plot items.

Use caution when iterating these lists, as removing/detaching an item will invalidate the iterator. Instead you can place pointers to objects to be removed in a removal list, and traverse that list later.

强调我的。

关于c++ - 崩溃 : this may be due to a corruption of the heap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29491024/

相关文章:

c++ Qt Qwt构建问题

plot - QWT zoomer plus panner 连续重绘

openlayers-3 - 如何缓存 QGIS Server WMS?

c++ - 隐藏自定义 QwtSymbol 的边界矩形

c++ - 数组中的默认值

html - 让 c++ 程序调用 html 函数/事件监听器

python - 如何从外部运行 QGIS 的 python 脚本

python - 我在哪里可以找到 QGIS 的所有 python 函数的概述

C++ : Automatically run function when derived class is constructed

c++ - 如何在 C++ 中处理时间