Results 1 to 5 of 5

Thread: qfile read from last position

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2012
    Location
    Chennai/India
    Posts
    8
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default qfile read from last position

    i want to plot curve by reading 512 data from text file for each 250ms,but i can plot the curve by reading 512 data once and how can i read the text file from last read position in the file to update my plot.And my code is,

    Qt Code:
    1. MainWin::MainWin( QWidget *parent): QwtPlot( parent ){
    2.  
    3. setAxisScale( xBottom, 0.0,512.0,50.0 );
    4. setAutoReplot(true);
    5. setAxisScale( yLeft, 0.0, 255.0,50.0);
    6. canvas()->setLineWidth( 1 );
    7. canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
    8. canvas()->setBorderRadius( 1 );
    9. QPalette canvasPalette;
    10. canvasPalette.setColor( QPalette::Background, QColor( 30, 30, 50 ) );
    11. canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
    12. canvas()->setPalette( canvasPalette );
    13.  
    14. QwtPlotCurve *d_curves=new QwtPlotCurve();
    15. d_curves->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol, Qt::NoBrush,
    16. QPen( Qt::black ), QSize( 5, 5 ) ) );
    17. d_curves->setPen( QPen( QColor( 200, 150, 50 ), 1.5 ) );
    18. d_curves->setStyle( QwtPlotCurve::Lines );
    19. d_curves->setRenderHint( QwtPlotCurve::RenderAntialiased );
    20. d_curves->setRawSamples( xval, yval, Size );
    21. d_curves->attach(this);
    22. (void)startTimer(250);
    23.  
    24. }
    25. void MainWin::timerEvent(QTimerEvent *)
    26. {
    27. newCurveData();
    28. replot();
    29.  
    30. }
    31.  
    32. void MainWin::newCurveData()
    33. {
    34.  
    35. QFile file("val/measure.txt");
    36. if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
    37. printf("cannot open");
    38. }
    39. QTextStream in(&file);
    40. int j=0;
    41. for(j=0;j<=512;j++)
    42. {
    43. QString line=in.readLine();
    44. xval[j] = j;
    45. yval[j]=line.toDouble();
    46.  
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by high_flyer; 20th July 2012 at 12:57. Reason: code tags

Similar Threads

  1. Can't read large file (2.5GB) with QFile
    By enricong in forum Qt Programming
    Replies: 6
    Last Post: 18th July 2011, 04:14
  2. Read and Write file to/from QFile
    By ruben.rodrigues in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2011, 14:57
  3. QFile - QDataStream read and write each character
    By nhs_0702 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2010, 19:03
  4. QFile::read failing on XP SP3
    By drescherjm in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2009, 21:59
  5. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 20:24

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
  •  
Qt is a trademark of The Qt Company.