PDA

View Full Version : QwtPlotCurve error on multimple overlayed curves



Halpha
19th September 2012, 16:40
Hi

I am experiencig a weird problem with the qwtplotcurve..

I need to plot shapes on a plot, and I am using the qwtplotcurve class. The problem is that the number of shapes is not fixed
so I used the dynamic allocation:

QwtPlotCurve *i_Curve = new QwtPlotCurve[ 100];

all works, except when I close my application: at exit an error rises...

does anyboby suggest a solution or an alternative approach to my problem.

Thank in advance!

H

Uwe
19th September 2012, 16:49
delete [] != delete: always allocate plot items ( here curves ) one by one - f.e in a loop.

Another option is: plot->setAutoDelete( false ) - but then you have to delete the curves ( and all other plot items ) on your own.

Uwe

Halpha
19th September 2012, 17:40
delete [] != delete: always allocate plot items ( here curves ) one by one - f.e in a loop.

Another option is: plot->setAutoDelete( false ) - but then you have to delete the curves ( and all other plot items ) on your own.

Uwe

already tried without success, if I try to deallocate before the exit another error pops up..

what do you mean with: "allocate one by one in a loop"?

i need to plot the same shapes inside my plot, in different positions but with the same specs. I thought to allocate a maximum number of elements an use only the ones needed time by time.

Uwe
19th September 2012, 19:53
Well for C++ basics please continue on list dedicated to C++ questions.

But beside this I don't see how allocating 100 curves ( even if implemented correctly ) helps for anything - at least not without knowing what you mean by "specs".

Uwe

Halpha
20th September 2012, 11:57
specs-> specifications

i need to plot all those curves with the same marker, colors etc.

the error rises only if QwtPlotCurve *i_Curve = new QwtPlotCurve[ 100]; is called.

if i comment that the program works perfectly.


the application runs with 5 threads with consumer producer architecture for real time plotting and elaboration.
i need those 100 curves to draw polygons in different positions of my plot to underline an event.

Uwe
20th September 2012, 12:27
i need to plot all those curves with the same marker, colors etc..
What has absolutely nothing to do with allocating 100 curves in advance.
Instead derive from QwtPlotCurve and set the common attributes in the constructor or use a curve factory.


the error rises only if QwtPlotCurve *i_Curve = new QwtPlotCurve[ 100]; is called.
Sure - again: read about delete and delete [] in your C++ book.

Maybe you want to do the following:


QwtPlotCurve *curves[100];
for ( int i = 0; i < 100; i++ )
curve[i] = new QwtPlotCurve();

Uwe

Halpha
21st September 2012, 13:24
thanks Uwe fot your patience and answers.

btw the error was genereate by 2 different elements:
first-> you allocation procedure is correct, it works perfectly
second-> if I want to use different curves i must initialize also differen symbols

the error was genereated because i initilized just 1 simbol, using it for all the curves.. So during the closing procedure, when first curve is deallocated the program looses the reference to the simbol (pointer) stored in the other curves..


here the working code



QwtPlotCurve *curves[100];
QwtSymbol *Curves_Symbol[100];
for ( int i = 0; i < 100; i++ ){
curves[i] = new QwtPlotCurve();
Curves_Symbol[i] = new QwtSymbol( QwtSymbol::Cross, QBrush( Qt::yellow ), QPen( Qt::yellow, 2 ), QSize( 2, 2 ) );

curves[i]->setPen( QPen( Qt::yellow, 1 ) ), curves[i]->setRenderHint( QwtPlotItem::RenderAntialiased, true );
curves[i]->setSymbol( Curves_Symbol[i] );
curves[i]->attach( ui.qwtPlot );
}




Tnx again.