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

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

    hello every body, i am a student in engineering, graduation stage.
    i want to read data from file has an extension of .ecg or any extension and plot these data.
    how can i do this ?
    i am using qt 4.7.4 version
    plz help me as i am really need this program.
    thanks in advance

  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 seem to be expecting some QReadAndInterpretECGorAnyFile class for an unspecified meaning of "ECG" or "any" file... it isn't going to happen.

    The general proces implied by your general requirement is; open the file (QFile), read and interpret the file content (QFile, QIODevice, and/or QTextStream), and do something with the resulting data.

    Qwt offers reasonable plotting facilities and also has a sub-forum here.

  3. #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 ?

    thanks a lot for your help
    but when i use this code i have some errors
    i am using GUI application
    can you help me to fix this?. sorry for annoying you but i am a beginner ... thanks in advance

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


    and the errors are:
    C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:38: error: C2248: 'QWidget::data' : cannot access private member declared in class 'QWidget'
    C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:38: error: C2440: '=' : cannot convert from 'double *' to 'QWidgetData *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:41: error: C2248: 'QWidget::data' : cannot access private member declared in class 'QWidget'
    C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:41: error: C2679: binary '=' : no operator found which takes a right-hand operand of type 'double' (or there is no acceptable conversion)
    C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtGui/qwidget.h(143): could be 'QWidgetData &QWidgetData::operator =(const QWidgetData &)'
    while trying to match the argument list '(QWidgetData, double)'
    C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:43: error: C2065: 'dataSize' : undeclared identifier
    Last edited by wysota; 20th March 2012 at 08:20. Reason: missing [code] tags

  4. #4
    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 ?

    Where is the variable data declared? It appears that it is not declared, and coincidentally there is an existing member data of incompatible type inherited from QWidget, which is what the error message is telling you.

    Rather than using a bare array (i.e. data) you should consider using QList or QVector which will manage the memory for you. You could also consider going straight from the line read from file to a QList<double> without the intervening QStringList.

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

    ahmed ali (20th March 2012)

  6. #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 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

  7. #6
    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?

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

    ahmed ali (20th March 2012)

  9. #7
    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

  10. #8
    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.

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

    ahmed ali (20th March 2012)

  12. #9
    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

  13. #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 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

  14. #11
    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.

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

    ahmed ali (21st March 2012)

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

    Default how to load file and plot it plot using Qwt

    Hello Everybody
    I have a file with extension of ECG (Demo.ecg) that is contain a ECG signals, but i have a problem to load this file and plot it using Qwt
    http://www.mediafire.com/?3ngo1nwxcbb6z9c
    can any one help me?
    thanks in advance

  17. #13
    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 to load file and plot it plot using Qwt

    Why start a new thread for the same problem? Please attach the file to your post rather than leave it on on a third-party site.

    Now we know that the ECG file is not a text file this somewhat changes the solution you were attempting in the other thread. QTextStream is not the correct tool for the job: the input is not text. Do you know what the binary data layout is?

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

    ahmed ali (27th March 2012)

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

    Default Re: how to load file and plot it using Qwt

    thanks a lot
    sorry for posting new thread about the same problem.

    what do you mean by "binary data layout"?
    if you mean the data of ecg file,
    yes, the binary data layout is (for example)

    -0.00300000000000000
    -0.00200000000000000
    -0.00100000000000000
    0
    0.00200000000000000
    0.00400000000000000
    0.00400000000000000
    0.00600000000000000
    0.00600000000000000
    0.00700000000000000
    0.00800000000000000
    0.00900000000000000
    0.0100000000000000
    0.0100000000000000
    0.00800000000000000
    0.00600000000000000
    0.00200000000000000
    -0.00100000000000000
    -0.00300000000000000
    -0.00300000000000000
    -0.00300000000000000
    -0.00100000000000000
    0.00100000000000000
    0.00400000000000000
    0.00500000000000000
    0.00400000000000000
    0.00200000000000000
    -0.00200000000000000
    -0.004000
    My problem is how to load these data from the file of extension of ECG and plot it
    can i convert this file format to txt format ? but using Qt?
    thanks in advance

  20. #15
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to load file and plot it using Qwt

    As far I could find *.ecg file is a binary file.
    If you have some documentation what is the format of the file (binary layout) then I can help you how to read those data and how to plot them with Qwt6.

  21. The following user says thank you to MarekR22 for this useful post:

    ahmed ali (27th March 2012)

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

    Default Re: how to load file and plot it using Qwt

    Quote Originally Posted by MarekR22 View Post
    As far I could find *.ecg file is a binary file.
    If you have some documentation what is the format of the file (binary layout) then I can help you how to read those data and how to plot them with Qwt6.
    thanks in advance for your help i will try to find some documentation what is the format of the file (binary layout)

    master of zen <<< OK

  23. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: how to load file and plot it using Qwt

    Quote Originally Posted by ahmed ali View Post
    My problem is how to load these data from the file of extension of ECG and plot it
    can i convert this file format to txt format ?
    You have to understand one thing. The extension of a file does not determine its contents. There may be several types of file using the same file extension. I have seen one file format for electrocardiography but that was indeed a textual format (as far as I read on their webpage) and what you provided is a binary file. Without reverse engineering the file it is not possible for us to determine the layout of the file and I'm sure nobody here is going to spend hours of their time analyzing your file. So please do your homework and find out (maybe from a person who gave you the file?) what the file really is and whether there are already existing libraries that can read this format and output numerical data such as those you have pasted in your post. Once you have those numbers, plotting them should be simple.
    Last edited by wysota; 27th March 2012 at 14:02.
    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.


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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.