Results 1 to 5 of 5

Thread: qfile read from last position

  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 13:57. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qfile read from last position

    You can either reuse the same text stream object or use QTextStream::seek() and QTextStream::pos()
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2012
    Location
    Chennai/India
    Posts
    8
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: qfile read from last position

    thanks for your reply i will try to do it.


    Added after 1 4 minutes:


    now i changed the code to,
    Qt Code:
    1. void MainWin::newCurveData()
    2. {
    3.  
    4. QFile file("val/measure.txt");
    5. if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
    6. printf("cannot open");
    7. }
    8. QTextStream in(&file);
    9. int j=0;
    10. in.seek(kval);
    11. for(j=0;j<=512;j++)
    12. {
    13. QString line=in.readLine();
    14. xval[j] = j;
    15. yval[j]=line.toDouble();
    16. kval=in.pos();
    17.  
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    so now it s updating my plot.And could u tell me can i read from '/dev/spidev' file using this same method.
    Last edited by wysota; 21st July 2012 at 12:03. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qfile read from last position

    I don't see why not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2012
    Location
    Chennai/India
    Posts
    8
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: qfile read from last position

    oh thank u

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, 05:14
  2. Read and Write file to/from QFile
    By ruben.rodrigues in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2011, 15:57
  3. QFile - QDataStream read and write each character
    By nhs_0702 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2010, 20:03
  4. QFile::read failing on XP SP3
    By drescherjm in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2009, 22:59
  5. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 21: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.