Results 1 to 7 of 7

Thread: QwtPlotCurve error on multimple overlayed curves

  1. #1

    Default QwtPlotCurve error on multimple overlayed curves

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotCurve error on multimple overlayed curves

    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

  3. #3

    Default Re: QwtPlotCurve error on multimple overlayed curves

    Quote Originally Posted by Uwe View Post
    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.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotCurve error on multimple overlayed curves

    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

  5. #5

    Default Re: QwtPlotCurve error on multimple overlayed curves

    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.

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotCurve error on multimple overlayed curves

    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:

    Qt Code:
    1. QwtPlotCurve *curves[100];
    2. for ( int i = 0; i < 100; i++ )
    3. curve[i] = new QwtPlotCurve();
    To copy to clipboard, switch view to plain text mode 
    Uwe

  7. #7

    Default Re: QwtPlotCurve error on multimple overlayed curves

    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

    Qt Code:
    1. QwtPlotCurve *curves[100];
    2. QwtSymbol *Curves_Symbol[100];
    3. for ( int i = 0; i < 100; i++ ){
    4. curves[i] = new QwtPlotCurve();
    5. Curves_Symbol[i] = new QwtSymbol( QwtSymbol::Cross, QBrush( Qt::yellow ), QPen( Qt::yellow, 2 ), QSize( 2, 2 ) );
    6.  
    7. curves[i]->setPen( QPen( Qt::yellow, 1 ) ), curves[i]->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    8. curves[i]->setSymbol( Curves_Symbol[i] );
    9. curves[i]->attach( ui.qwtPlot );
    10. }
    To copy to clipboard, switch view to plain text mode 



    Tnx again.

Similar Threads

  1. Replies: 8
    Last Post: 18th October 2012, 07:23
  2. QwtPlotcurve multiple curves
    By garij in forum Qwt
    Replies: 4
    Last Post: 10th May 2012, 12:30
  3. Replies: 1
    Last Post: 1st December 2010, 11:02
  4. Replies: 1
    Last Post: 16th September 2009, 11:23
  5. Replies: 2
    Last Post: 14th April 2008, 11:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.