PDA

View Full Version : same QwtColorMap object in plot and color-bar causes crash



rainman110
21st November 2011, 21:29
Hi,

the spectrogram example uses two separate color map objects to display the color-bar and the plot itself. In the code this is done by the lines


d_spectrogram->setColorMap( new ColorMap());
rightAxis->setColorMap( zInterval, new ColorMap());

Now in my real project (which is inspired by this example) I would like to maintain only one single colormap object, because it should be modified by the gui. However, if the same colormap object is given to the plot and the color-bar according to


ColorMap * map = new ColorMap();
d_spectrogram->setColorMap( map );
rightAxis->setColorMap( zInterval, map);

the application crashes during in the destructor because both the colorbar (QwtScaleWidget) and the plot try to delete the same object which results in a double delete. How can I avoid this behaviour? I think QWT needs smart pointers as QT does to avoid such problems. Are there any workarounds or should I keep 2 objects and keep them in sync?

Thanks, Martin

alketi
13th February 2019, 20:16
Well, almost 8 years later and I just ran into this same issue. My spectrogram app crashing on exit. Ouch. I've spent more time searching and looking through valgrind outputs to find the cause than I'll admit.

In case anyone else finds this, you have to create separate ColorMap instances and feed them separately into the Spectrogram and Axis objects. You cannot reuse a single object as you would do elsewhere in Qt, or your Qwt app will crash on exit with a double-delete.

Uwe, if you're still supporting the project, it would be really nice if Qwt used QPointers (or similar) internally to prevent this issue, or at least, documented it in the QwtSpectrogram class. Great library otherwise. Cheers.