Results 1 to 3 of 3

Thread: Read contents of QwtSeriesData<QPointF>

  1. #1
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Read contents of QwtSeriesData<QPointF>

    Hi all,

    Qt Code:
    1. QwtSeriesData<QPointF>* coordinates = new FunctionData(::sin);
    To copy to clipboard, switch view to plain text mode 

    Considering the line above, I have a question on how to read the values from the QwtSeriesData<QPointF> object. The code I am dealing with accept both constructions below, but the second one is preferable.

    Qt Code:
    1. MyPlotCurve *sinCurve = guiComVisGraf->createCurve("Seno", coordinates );
    2. MyPlotCurve *sinCurve = guiComVisGraf->createCurve("Seno", size, x, y);
    To copy to clipboard, switch view to plain text mode 

    So I am trying this

    Qt Code:
    1. int size = coordinates->size();
    2. double *x = new double[size];
    3. double *y = new double[size];
    4. for(int i = 0; i < size; i++){
    5. x[i] = coordinates->sample(i).x();
    6. y[i] = coordinates->sample(i).y();
    7. }
    8. MyPlotCurve *sinCurve = guiComVisGraf->createCurve("Seno", size, x, y);
    To copy to clipboard, switch view to plain text mode 

    This way I am reading "0" for all "i". There is probably a neat misunderstanding in my code, I would like to ask for help in find it. Thanks in advance.

  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: Read contents of QwtSeriesData<QPointF>

    Assuming that FunctionData is taken from the sinusplot example the code above doesn't make much sense - together with the rest of your question.

    Better take this code for learning the very basics of how to show a curve on a QwtPlot: http://qwt.svn.sourceforge.net/viewv...75&view=markup.

    Uwe

    Qt Code:
    1. int main( int argc, char **argv )
    2. {
    3. QApplication a( argc, argv );
    4.  
    5. QwtPlot plot;
    6. plot.setTitle( "Plot Demo" );
    7. plot.setCanvasBackground( Qt::white );
    8. plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    9. plot.insertLegend( new QwtLegend() );
    10.  
    11. QwtPlotGrid *grid = new QwtPlotGrid();
    12. grid->attach( &plot );
    13.  
    14. QwtPlotCurve *curve = new QwtPlotCurve();
    15. curve->setTitle( "Some Points" );
    16. curve->setPen( QPen( Qt::blue, 4 ) ),
    17. curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    18.  
    19. QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
    20. QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    21. curve->setSymbol( symbol );
    22.  
    23. QPolygonF points;
    24. points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
    25. << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
    26. << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    27. curve->setSamples( points );
    28.  
    29. curve->attach( &plot );
    30.  
    31. plot.resize( 600, 400 );
    32. plot.show();
    33.  
    34. return a.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Read contents of QwtSeriesData<QPointF>

    May be the problem was not clearly stated. I was not reading the values corresponding to the sinus curve inside coordinates. For some reason it seems that the data become available in coordinates only after a replot. May be some one can discuss what happens behind the scenes...

    For me it was sufficient to do this:

    Qt Code:
    1. double *xSin = new double[size];
    2. double *ySin = new double[size];
    3. for(int i = 0; i < size; i++){ /* Gera pontos do seno. */
    4. xSin[i] = i;
    5. ySin[i] = ::sin(i);
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QwtSeriesData and boundingRect()
    By baray98 in forum Qwt
    Replies: 2
    Last Post: 12th January 2012, 06:49
  2. How to read changing file contents
    By tomkonikkara in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2011, 19:11
  3. Read contents from the file using QHTTP Read()?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 21st June 2011, 08:03
  4. Replies: 8
    Last Post: 17th June 2011, 00:35
  5. Replies: 1
    Last Post: 18th June 2010, 11:21

Tags for this Thread

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.