PDA

View Full Version : Unset raster data pointer in QwtPlotSpectrogram without deleting it?



raphael.lencrerot
27th May 2013, 16:04
Hi Uwe,
I'm facing a small problem here related to my design.
In my design, I have a QwtMatrixRasterData that is defined/declared in a class that handle IO and fill it with suited data. This class is also in charge of deleting this guy.
But I realize that QwtPlotSpectrogram tries to delete also this raster data when the destructor is invoked. So I have a double free corruption happening. Is there a way to call a "unSetData()" method to remove the pointer stored in the QwtPlotSpectrogram then avoid to destroy it?
Am I supposed to let QwtPlotSpectrogram destroy the QwtMatrixRasterData so that I have to change the way to address this data?

I went down to the code and I saw that it is not implement the way I could have the raster data deleted outside. But probably their is a possibility?


Thanks by advance.

Uwe
29th May 2013, 10:01
QwtMatrixRasterData is a bridge between plot item and the real data, that is here stored as a QVector. What is the reason for keeping a copy such a bridge in your code ?

Note that QVector is implicitly shared - like all Qt containers. So you can fill a QVector in your class and copy it then to the raster data object easily without any overhead.

Uwe

raphael.lencrerot
29th May 2013, 12:13
Thank Uwe,
this is finally what I have done. I removed the QwtMatrixRasterData object from my IO class. I still have the QVector handled by this class.

Since the QVector content can change (user move somewhere else to see another slice, for instance in depth) do I have to call following code each time QVector is updated?


QwtMatrixRasterData* raster=dynamic_cast<QwtMatrixRasterData*>(spectro_seismic->data());
raster->setValueMatrix(seismic->data(),seismic->nx());


I tried without but the updated content was not ploted.

Thank again.

Uwe
29th May 2013, 12:41
You are changing the data behind the back of the item - what means that its internal caches ( see QwtPlotRasterItem::invalidateCache() ) are not invalidated. Better create a new QwtMatrixRasterData object each time you are updating the value to avoid having to deal with them.

Of course you also need to have a final replot to rebuild the plot.

Uwe

raphael.lencrerot
29th May 2013, 12:56
Ok,
thanks for all.