Results 1 to 20 of 28

Thread: How Can i Load data from file.ecg and plot it ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    15
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: How Can i Load data from file.ecg and plot it ?

    thanks a lot ChrisW67,
    I tried to use this code:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include<QFile>
    4. #include<QtCore>
    5. #include<QtGui>
    6. #include<QList>
    7. #include<QTextStream>
    8.  
    9. MainWindow::MainWindow(QWidget *parent) :
    10. QMainWindow(parent),
    11. ui(new Ui::MainWindow)
    12. {
    13. ui->setupUi(this);
    14. ui->label->setText("Hello User :)");
    15.  
    16. }
    17.  
    18. MainWindow::~MainWindow()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void MainWindow::on_pushButton_clicked()
    24. {
    25. QFile file("C:/ahmad/ecg test/tst.txt");
    26. if(!file.open( QFile::ReadOnly | QFile::Text))
    27. {
    28. ui->label->setText(" OOP : File Cant be Opened");
    29. return;
    30. }
    31. QList<double> list;
    32. QTextStream in(&file);
    33. ui->label->setText("DONE : file opened");
    34. while (!in.atEnd())
    35. {
    36. list << in.readLine();
    37. }
    38. file.close();
    To copy to clipboard, switch view to plain text mode 

    but unfortunately have some error too
    C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:36: error: C2678: binary '<<' : no operator found which takes a left-hand operand of type 'QList<T>' (or there is no acceptable conversion)

    and if i have loaded the data to Qlist<double> list , how can i then plot these data ?
    Last edited by wysota; 20th March 2012 at 08:21. Reason: missing [code] tags

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How Can i Load data from file.ecg and plot it ?

    You are trying to append a QString to a list of doubles. Perhaps you need to convert to double like you were before. Is there only one number on each line?

  3. The following user says thank you to ChrisW67 for this useful post:

    ahmed ali (20th March 2012)

  4. #3
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    15
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: How Can i Load data from file.ecg and plot it ?

    yes, every line has one value
    (i.e 1.8600000e+03
    1.8640000e+03
    1.8660000e+03
    1.8550000e+03
    1.8660000e+03
    1.8760000e+03

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How Can i Load data from file.ecg and plot it ?

    Hmmm you need at least two coordinates to plot anything.
    The values you have are probably Y values where time increases in constant.

    try this:
    Qt Code:
    1. MainWindow::MainWindow( QWidget* p )
    2. :
    3. plot( new QwtPlot( this ) ), // create plot widget
    4. x( QVector< double >() ),
    5. y( QVector< double >() )
    6. {
    7. QToolBar* tb = this->addToolBar( "File" );
    8. tb->addAction( "Open File", this, SLOT( openFile() ) );
    9. this->setCentralWidget( this->plot );
    10. }
    11.  
    12. void MainWindow::openFile( void )
    13. {
    14. QString str = QFileDialog::getOpenFileName( this );
    15. if( !str.isEmpty() )
    16. {
    17. QwtPlotCurve* curve = this->getCurve( str );
    18.  
    19. if( !curve )
    20. {
    21. return;
    22. }
    23.  
    24. curve->attach( this->plot );
    25. this->plot->replot();
    26. }
    27. }
    28.  
    29. QwtPlotCurve* MainWindow::getCurve( const QString& path )
    30. {
    31. int size = 0;
    32.  
    33. QFile src( path );
    34. if( !src.open( QIODevice::ReadOnly ) )
    35. {
    36. return NULL;
    37. }
    38.  
    39. while( !src.atEnd() )
    40. {
    41. // x is placeholder if you don't have anything better
    42. this->x.append( size ); // this->y is QVector< double > which need to be kept alive as long as curve uses the data!
    43. this->y.append( src.readLine().toDouble() ); // this->x is QVector< double > which need to be kept alive as long as curve uses the data!
    44. ++size;
    45. }
    46.  
    47. c->setSamples( this->x.at( idx ).data(), this->y.at( idx ).data(), size );
    48. return c;
    49. }
    To copy to clipboard, switch view to plain text mode 
    It's all you need to load a file and plot it.

  6. The following user says thank you to Spitfire for this useful post:

    ahmed ali (20th March 2012)

  7. #5
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    15
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: How Can i Load data from file.ecg and plot it ?

    thanks a lot i will try it now and i will reply

  8. #6
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    15
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: How Can i Load data from file.ecg and plot it ?

    thanks a lot
    i have tried it but having some errors
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include<QString>
    4.  
    5. #include <qwt_plot.h>
    6.  
    7.  
    8. MainWindow::MainWindow( QWidget* p ):
    9. plot( new QwtPlot( this ) ), // create plot widget
    10. x( QVector< double >() ),
    11. y( QVector< double >() )
    12. {
    13. QToolBar* tb = this->addToolBar( "File" );
    14. tb->addAction( "Open File", this, SLOT( openFile() ) );
    15. this->setCentralWidget( this->plot );
    16. }
    17.  
    18. void MainWindow::openFile( void )
    19. {
    20. QString str = QFileDialog::getOpenFileName( this );
    21. if( !str.isEmpty() )
    22. {
    23. QwtPlotCurve* curve = this->getCurve( str );
    24.  
    25. if( !curve )
    26. {
    27. return;
    28. }
    29.  
    30. curve->attach( this->plot );
    31. this->plot->replot();
    32. }
    33. }
    34.  
    35. QwtPlotCurve* MainWindow::getCurve( const QString& path )
    36. {
    37. int size = 0;
    38.  
    39. QFile src( path );
    40. if( !src.open( QIODevice::ReadOnly ) )
    41. {
    42. return NULL;
    43. }
    44.  
    45. while( !src.atEnd() )
    46. {
    47. // x is placeholder if you don't have anything better
    48. this->x.append( size ); // this->y is QVector< double > which need to be kept alive as long as curve uses the data!
    49. this->y.append( src.readLine().toDouble() ); // this->x is QVector< double > which need to be kept alive as long as curve uses the data!
    50. ++size;
    51. }
    52.  
    53. c->setSamples( this->x.at( idx ).data(), this->y.at( idx ).data(), size );
    54. return c;
    55. }
    56. QMainWindow(parent),
    57. ui(new Ui::MainWindow)
    58. {
    59. ui->setupUi(this);
    60. }
    61.  
    62. MainWindow::~MainWindow()
    63. {
    64. delete ui;
    65. }
    To copy to clipboard, switch view to plain text mode 

    1st problem is i QWT library not installed and i have read lot of threads but unfortunately i cant install it
    2nd problem is i am a beginner and i feel there is some thing wrong in my above code
    can i get help to fix these errors?
    thanks in advance

  9. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How Can i Load data from file.ecg and plot it ?

    1st problem is i QWT library not installed and i have read lot of threads but unfortunately i cant install it
    If this is the case then you cannot even compile the code above.

    You do not need forum threads, blogs or Google searches to install Qwt. The instructions are in the INSTALL file that comes with the Qwt source (as Uwe is constantly explaining).

    If you follow the instructions in the INSTALL file, not somewhere else, and strike a problem then post a description of exactly what you did, and what you got that seems broken or wrong. The Qwt sub-forum might be a better place for that.

    2nd problem is i am a beginner and i feel there is some thing wrong in my above code
    Possibly, maybe even probably, but wait until you can build it before you worry about this.

  10. The following user says thank you to ChrisW67 for this useful post:

    ahmed ali (21st March 2012)

  11. #8
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    15
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: How Can i Load data from file.ecg and plot it ?

    Thanks a lot, but i am wondering why there is no video tutorial that show us how to install QWT library as i have tried several times but always there are errors
    all i can say now i will try again and thanks for your help

  12. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How Can i Load data from file.ecg and plot it ?

    There's no video tutorial because the instructions in the INSTALL file are both complete and adequate.

    Since you have not explained the problem you are experiencing actually is we are unable to help.

  13. The following user says thank you to ChrisW67 for this useful post:

    ahmed ali (21st March 2012)

  14. #10
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    15
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: How Can i Load data from file.ecg and plot it ?

    thanks a lot,
    I have done these steps to install QWT in my windows:
    1.i downloaded the qwt library called qwt-6.0.1
    2.unzipped it to C:/Qwt
    3.then i started QT command prompt i found it in ( start > QtSDK > Desktop > Qt 4.8.0 for Desktop (MSVC 2010)
    4.cd C:\QWT\qwt-6.0.1 this is the folder where i put the unzipped library
    5.qmake qwt.pro this command executed successfully
    6. when i try to execute nmake or nmake install i have this msg: 'nmake' is not recognized as an internal or external command, operable program or batch file

    i stooped at this point can any body help me ?
    thanks in advance

  15. #11
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How Can i Load data from file.ecg and plot it ?

    Try mingw32-make instead.

  16. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How Can i Load data from file.ecg and plot it ?

    Quote Originally Posted by ahmed ali View Post
    6. when i try to execute nmake or nmake install i have this msg: 'nmake' is not recognized as an internal or external command, operable program or batch file
    The Qt command prompt set the shell PATH to find the components of the Qt SDK. If, and only if, you are using the bundled MingW compiler this is also present in the environment.

    You are using the Microsoft C++ compiler that expects a raft of stuff in its environment, the most important of which is the compiler/tool binaries in the PATH. When you use Microsoft's IDE this is all hidden for you (IMHO to the detriment of understanding). Microsoft, since at least the early '90s, provides a shell script called vcvars32.bat for Setting the Path and Environment Variables for Command-Line Builds (there may be a 64-bit version also). Execute this first after opening the Qt command prompt and you should find that things work better. You will need this to build Qt or any third party library, module etc. built from the command line: this is not unique to Qwt. I cannot tell you which version or where you have the Microsoft compiler installed so I cannot give you the exact command to type.

    I think it perfectly reasonable that every set of install instructions for a library, like Qwt, assumes that the programmer has a working compiler environment. To expect otherwise is to expect the library author to have access to every possible permutation of system and compiler and produce a blow-by-blow set of instructions for each. Having done that you can be 100% certain that they will still not match some programmer's particular environment, and they will complain. The majority of blogs and other attempts to provide blow-by-blow instructions for Qwt fail in that way and generally demonstrate the lack of understanding of the author.

  17. The following user says thank you to ChrisW67 for this useful post:

    ahmed ali (22nd March 2012)

  18. #13
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    15
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: How Can i Load data from file.ecg and plot it ?

    Master of zen << thanks a lot for your advice, but when i asked for a video tutorial this is as i am a beginner in Qt and i thought that i have something wrong in my setting.


    ChrisW67 << Lot of thanks for helping me, i have read your Reply and i will try it now.

Similar Threads

  1. Replies: 12
    Last Post: 31st October 2010, 17:08
  2. Load data from different ui
    By Xtresis in forum Newbie
    Replies: 2
    Last Post: 29th September 2010, 11:57
  3. Way to load all of data from 2 tables into one QTableView?
    By Kevin Hoang in forum Qt Programming
    Replies: 8
    Last Post: 3rd April 2010, 09:42
  4. Saving pure plot data to image file
    By Debilski in forum Qwt
    Replies: 4
    Last Post: 7th April 2009, 17:02
  5. Replies: 6
    Last Post: 26th March 2009, 05:45

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.