Uwe Rathmann | 16 Apr 21:08

Re: Help with understanding QwtRasterData needed

On Wednesday 16 April 2008 20:09, Matthias Pospiech wrote:

> It is the copy from the example code. I have no idea how to change it to
> be correct.

QwtRasterData *SpectrogramData::copy() const
{
        SpectrogramData *clone = new SpectrogramData();
        clone->setData(m_Array, m_DataSize.x, m_DataSize.y);
        ...
        return clone;
}

> I have to deal with no-Qt libaries, especially math libaries which
> require double arrays.
> Using QVector arrays would definetly be nicer, ...  

With QVector<double>::data() you have a double array.

> ... but would mean that I have to copy the array multiple times between each
> libary.

Your implementation of setData copies and each call of SpectrogramData::copy ( 
implicitely called by Qwt) would do another copy. If you would use a QVector 
inside of SpectrogramData you could write:

 void setData(double * Array, int sizex, int sizey)
 {
        ...
        m_Array.resize(size);
        memcpy(m_Array.data(), Array, size * sizeof(double));
 }

QwtRasterData *SpectrogramData::copy() const
{
        SpectrogramData *clone = new SpectrogramData();
        ...
        clone->m_Array = m_Array;
        return clone;
}

But if you have control over the lifetime of your array I would copy the Array 
pointer only and avoid copying at all. If you have already a smart pointer 
concept available use it, otherwise you can also put your array into a 
structure derived from a QObject, that can be protected using QPointer.

Uwe

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

Gmane