Page 1 of 2 12 LastLast
Results 1 to 20 of 33

Thread: display a plot point by point

  1. #1
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default display a plot point by point

    hello
    i finally downloaded qwt from svn and everything is ok (Qt 4.5 ,qwt 5.3.0,windows xp)
    now i need to display a plot point by point ,so i tried to create a retard with Qtimer ,but it doesn't work !

    no execution or complilation errors but i haven't the result i'm expecting
    it's my first program with qwt ,i'm following the pdf given with qwt 5.1.1
    the documentation for qwt 5.1.1 still useful ?

    thanks in advance
    Last edited by oswalidos; 9th March 2009 at 21:49.

  2. #2
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    maybe i'm not clear
    i simply want to see plot painting point by point because i'm working on a "real-time" application ,points will be available while my system is running ,so i plan to use Qthread to synchronize tasks .
    now i need to know how can i control displaying plots ?
    can i find signals or create signals to do such thing ?
    thanks for your help

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

    Default Re: display a plot point by point

    Can we see the code?
    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.


  4. #4
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    i just tried a code which stored data first ,after it display the curve

    Qt Code:
    1. #include <QtGui>
    2. #include <qwt_plot.h>
    3. #include <qwt_plot_curve.h>
    4. #include <qwt_plot_marker.h>
    5. #include <qwt_plot_curve.h>
    6. #include <qwt_legend.h>
    7. #include <qwt_series_data.h>
    8. #include <qwt_text.h>
    9. #include <math.h>
    10.  
    11. class Plot : public QwtPlot
    12. {
    13. public:
    14. Plot();
    15. };
    16.  
    17. Plot::Plot()
    18. {
    19. double x[100];
    20. double y1[100];
    21. double y2[100];
    22.  
    23. for(int i=0;i<100;i++){
    24. x[i]=i;
    25. y1[i]=i*i;
    26. y2[i]=i;
    27. }
    28.  
    29.  
    30. setTitle("Vitesse et angle de braquage en fonction du temps");
    31. insertLegend(new QwtLegend(), QwtPlot::RightLegend);
    32.  
    33. // Set axes
    34. setAxisTitle(xBottom, "Temps");
    35. setAxisScale(xBottom, 0.0, 100);
    36.  
    37. setAxisTitle(yLeft, "");
    38. setAxisScale(yLeft, 0.0, 100);
    39.  
    40. // add curves
    41. QwtPlotCurve *curve1 = new QwtPlotCurve("Vitesse");
    42. curve1->setPen(QPen(Qt::green));
    43. curve1->attach(this);
    44. curve1->setData(x, y1, 100);
    45.  
    46. QwtPlotCurve *curve2 = new QwtPlotCurve("Angle de Braquage");
    47. curve2->setPen(QPen(Qt::red));
    48. curve2->attach(this);
    49. curve2->setData(x, y2, 100);
    50.  
    51. // ...a horizontal line ...
    52. mY->setLabel(QString::fromLatin1("t ( ms )"));
    53. mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    54. mY->setLineStyle(QwtPlotMarker::HLine);
    55. mY->attach(this);
    56.  
    57. // ...a vertical line ...
    58. mX->setLabel(QString::fromLatin1("V ( m/s ) ,Ang ( rad/s )"));
    59. mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    60. mX->setLineStyle(QwtPlotMarker::VLine);
    61. mX->attach(this);
    62.  
    63. }
    64.  
    65.  
    66. int main(int argc, char **argv)
    67. {
    68. QApplication a(argc, argv);
    69.  
    70. Plot *myPlot = new Plot();
    71. myPlot->autoRefresh();
    72.  
    73. myPlot->resize(600,400);
    74. myPlot->show();
    75.  
    76. return a.exec();
    77. }
    To copy to clipboard, switch view to plain text mode 

    i want to change this code to display the curve step by step from (0,0) until (n,m) while time progressing !

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

    Default Re: display a plot point by point

    So where is your timer code?
    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.


  6. #6
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    i don't know where should i put timer .
    i'm asking how can i put timer ?
    i may should use other classes not Qwtplot cuz it needs the data stored to display curves .
    i tried with timer somewhere but it doesn't seem to work !
    i think i have to use others classes or some signals to control painting process .

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

    Default Re: display a plot point by point

    You should start a timer somewhere in your code and connect its timeout() signal to a custom slot that you have to implement. Inside the slot simply add more data to the curves.
    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.


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

    oswalidos (11th March 2009)

  9. #8
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    all data is fixed in constructor and can't be anywhere else .
    i think constructor can't be dynamic ,it's fixed since we instance an object from its class .
    if constructor still running when application is running that's mean is using more than thread ,that's can be right ?
    can i call constructor many times to change object's value and display it using timer ? i don't think so !

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

    Default Re: display a plot point by point

    In the constructor you can store the data in some array. Then you can add the data to the plot in some other place (like a slot).
    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.


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

    oswalidos (11th March 2009)

  12. #10
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    thanks for your help ,
    i'll try but logically data in constructor should be given only one time .

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

    Default Re: display a plot point by point

    I think you don't understand me. You can keep the data in two places - one of them is initialized and filled with data in the constructor. The other is the plot itself that is fed with the data from the first container using a timer.

    Here is a skeleton of a code doing what I mean:
    Qt Code:
    1. X::X(){
    2. for(int i=0;i<100;i++){
    3. x[i]=i;
    4. y1[i]=i*i;
    5. y2[i]=i;
    6. }
    7. curve1 = new QwtPlotCurve("Vitesse"); // curve1 is a member variable
    8. currentPointPosition = 1; // currentPointPosition is a member variable
    9. updateData();
    10. QTimer *timer = new QTimer(...);
    11. connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    12. timer->start(500);
    13. //...
    14. }
    15.  
    16. void X::onTimeout(){
    17. currentPointPosition++;
    18. if(currentPointPosition>100) currentPointPosition = 1;
    19. updateData();
    20. }
    21.  
    22. void X::updateData(){
    23. curve1->setData(x, y1, currentPointPosition);
    24. }
    To copy to clipboard, switch view to plain text mode 
    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.


  14. The following user says thank you to wysota for this useful post:

    oswalidos (11th March 2009)

  15. #12
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    hello ,
    thanks for the skeleton,i'm trying to apply your idea but i get blocked is something .
    when i define the macro Q_OBJECT an error appear :
    Qt Code:
    1. undefined refrence to vtabe for plot
    To copy to clipboard, switch view to plain text mode 

    my .pro is :
    Qt Code:
    1. TEMPLATE = app
    2. TARGET =
    3. DEPENDPATH += .
    4. INCLUDEPATH += C:\svn\qwt\qwt\src
    5. LIBS += C:\svn\qwt\qwt\lib\qwtd5.dll
    6. CONFIG += debug
    7.  
    8. # Input
    9. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    main.cpp :
    Qt Code:
    1. class Plot : public QwtPlot
    2. {
    3. //Q_OBJECT
    4. public:
    5. Plot();
    6. void pointByPoint();
    7.  
    8. private :
    9. QwtPlotCurve *curve1;
    10. int currentPointPosition;
    11. QTimer *timer;
    12. double *x;
    13. double *y;
    14.  
    15. /*
    16.   public slots:
    17.   void onTimeout(); */
    18. };
    19.  
    20.  
    21. Plot::Plot()
    22. {
    23. x=new double[100];
    24. y=new double[100];
    25.  
    26. for(int i=0;i<100;i++){
    27. x[i]=i;
    28. y[i]=i*i;
    29. }
    30.  
    31. //......
    32.  
    33. timer = new QTimer();
    34. //connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    35.  
    36. }
    37.  
    38. /*
    39. void Plot::onTimeout(){ //each timeout data will
    40.   currentPointPosition++; // be added to the curve
    41.   if(currentPointPosition>100) currentPointPosition = 1;
    42.   curve1->setData(x, y1, currentPointPosition);
    43. }
    44. */
    45.  
    46. void Plot::pointByPoint(){ //calling this method provoque painting curve "slowly"
    47. while(true){
    48. timer->start(500);
    49. }
    50. }
    51.  
    52.  
    53. int main(int argc, char **argv)
    54. {
    55. QApplication a(argc, argv);
    56.  
    57. Plot *myPlot = new Plot();
    58. myPlot->autoRefresh();
    59. myPlot->resize(600,400);
    60. myPlot->show();
    61.  
    62. //myPlot->pointByPoint();
    63.  
    64. return a.exec();
    65. }
    To copy to clipboard, switch view to plain text mode 

    thanks for your help

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

    Default Re: display a plot point by point

    Did you remember to run qmake after you added the macro?
    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.


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

    oswalidos (11th March 2009)

  18. #14
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    ohhh ,sorry ,i'm working with Qt creator and i forgot about qmake !!
    thanks a lot
    it works first time but now :
    this code still make error : undefined reference to "vtable for plot"
    Qt Code:
    1. class Plot : public QwtPlot
    2. {
    3. Q_OBJECT
    4. public:
    5. Plot();
    6. void pointByPoint();
    7.  
    8. private :
    9. QwtPlotCurve *curve;
    10. int currentPointPosition;
    11. QTimer *timer;
    12. double *x;
    13. double *y;
    14.  
    15. public slots:
    16. void onTimeout();
    17. };
    18.  
    19.  
    20. Plot::Plot()
    21. {
    22. x=new double[100];
    23. y=new double[100];
    24.  
    25. for(int i=0;i<100;i++){
    26. x[i]=i;
    27. y[i]=i*i;
    28. }
    29.  
    30. //........
    31.  
    32. timer = new QTimer();
    33. connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    34. }
    35.  
    36.  
    37. void Plot::onTimeout(){ //each timeout data will
    38. currentPointPosition++; // be added to the curve
    39. if(currentPointPosition>100) currentPointPosition = 1;
    40. curve->setData(x, y, currentPointPosition);
    41. }
    42.  
    43.  
    44. void Plot::pointByPoint(){ //calling this method provoque painting curve "slowly"
    45. for(int i=0;i<200;i++){
    46. timer->start(500);
    47. }
    48. }
    49.  
    50.  
    51. int main(int argc, char **argv)
    52. {
    53. QApplication a(argc, argv);
    54.  
    55. Plot *myPlot = new Plot();
    56. myPlot->autoRefresh();
    57. myPlot->resize(600,400);
    58. myPlot->show();
    59.  
    60. myPlot->pointByPoint();
    61.  
    62. return a.exec();
    63. }
    To copy to clipboard, switch view to plain text mode 

    it's a shame to ask many questions but there is no documentation about qwt and i'm still beginner .
    thanks for your help
    Last edited by oswalidos; 10th March 2009 at 22:52.

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

    Default Re: display a plot point by point

    Your issues are not related to Qwt. I'm even thinking about moving the thread to the newbie section of the board.

    The Q_OBJECT macro has to be placed in a header file (with .h extension). It's possible to place it in an implementation file but it requires some additional work so let's try avoiding it for now. So if your class declaration is in an implementation (.cpp) file, move it to a header file, add the file to your project and rerun qmake and make.
    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.


  20. The following user says thank you to wysota for this useful post:

    oswalidos (11th March 2009)

  21. #16
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    ok, i did but macro problem persist like this :

    D:/P2M/courbe/debug/courbe.exe exited with code 0
    Starting D:/P2M/courbe/debug/courbe.exe...
    D:/P2M/courbe/debug/courbe.exe exited with code -1073741819

    if i make macro and slots as a comment everything seems work !

    thx again

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

    Default Re: display a plot point by point

    If your application crashes, it's not because of lack or presence of Q_OBJECT macro. Use a debugger to see where it crashes and why.
    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.


  23. The following user says thank you to wysota for this useful post:

    oswalidos (11th March 2009)

  24. #18
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    i don't know how to debug in console mode but i tried with qt creator .
    when i run debug mode ,it still running with no information given ,debugger don't run until the first break point , it's written dbg running .

    plot.h :
    Qt Code:
    1. #include <QtGui>
    2. #include <qwt_plot.h>
    3. #include <qwt_plot_curve.h>
    4. #include <qwt_plot_marker.h>
    5. #include <qwt_plot_curve.h>
    6. #include <qwt_legend.h>
    7. #include <qwt_series_data.h>
    8. #include <qwt_text.h>
    9. #include <math.h>
    10.  
    11.  
    12. class Plot : public QwtPlot
    13. {
    14. Q_OBJECT
    15. public:
    16. Plot();
    17. ~Plot();
    18. void pointByPoint();
    19.  
    20. private :
    21. QwtPlotCurve *curve;
    22. int currentPointPosition;
    23. QTimer *timer;
    24. double *x;
    25. double *y;
    26.  
    27. public slots:
    28. void onTimeout();
    29. };
    To copy to clipboard, switch view to plain text mode 


    plot.cpp :
    Qt Code:
    1. #include "plot.h"
    2.  
    3. Plot::Plot()
    4. {
    5. x=new double[100];
    6. y=new double[100];
    7.  
    8. for(int i=0;i<100;i++){
    9. x[i]=i;
    10. y[i]=i*i;
    11. }
    12.  
    13. currentPointPosition=1;
    14.  
    15. setTitle("Vitesse et angle de braquage en fonction du temps");
    16. insertLegend(new QwtLegend(), QwtPlot::RightLegend);
    17.  
    18. // Set axes
    19. setAxisTitle(xBottom, "Temps");
    20. setAxisScale(xBottom, 0.0, 100);
    21.  
    22. setAxisTitle(yLeft, "");
    23. setAxisScale(yLeft, 0.0, 100);
    24.  
    25. // add curves
    26. curve = new QwtPlotCurve("Vitesse");
    27. curve->setPen(QPen(Qt::green));
    28. curve->attach(this);
    29. curve->setData(x, y, currentPointPosition);
    30.  
    31. // ...a horizontal line ...
    32. mY->setLabel(QString::fromLatin1("t ( ms )"));
    33. mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    34. mY->setLineStyle(QwtPlotMarker::HLine);
    35. mY->attach(this);
    36.  
    37. // ...a vertical line ...
    38. mX->setLabel(QString::fromLatin1("V ( m/s ) ,Ang ( rad/s )"));
    39. mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    40. mX->setLineStyle(QwtPlotMarker::VLine);
    41. mX->attach(this);
    42.  
    43. timer = new QTimer();
    44. connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    45. }
    46.  
    47.  
    48. void Plot::onTimeout(){ //each timeout data will
    49. currentPointPosition++; // be added to the curve
    50. if(currentPointPosition>100) currentPointPosition = 1;
    51. curve->setData(x, y, currentPointPosition);
    52. }
    53.  
    54.  
    55. void Plot::pointByPoint(){ //calling this method provoque painting curve "slowly"
    56. for(int i=0;i<200;i++){
    57. timer->start(500);
    58. }
    59. }
    60.  
    61. Plot::~Plot(){
    62. delete x;
    63. delete y;
    64. }
    To copy to clipboard, switch view to plain text mode 


    main.cpp
    Qt Code:
    1. #include "plot.h"
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. Plot *myPlot = new Plot();
    8. myPlot->autoRefresh();
    9. myPlot->resize(600,400);
    10. myPlot->show();
    11.  
    12. myPlot->pointByPoint();
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    .pro :
    Qt Code:
    1. TEMPLATE = app
    2. TARGET =
    3. DEPENDPATH += .
    4. INCLUDEPATH += C:\svn\qwt\qwt\src
    5. LIBS += C:\svn\qwt\qwt\lib\qwtd5.dll
    6. CONFIG += debug
    7.  
    8. # Input
    9. SOURCES += main.cpp \
    10. plot.cpp
    11. HEADERS += plot.h
    To copy to clipboard, switch view to plain text mode 

    i made as comment Q_OBJECT and my slot and it works ,i checked debugger too,it's ok with it under Qtcreator .

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

    Default Re: display a plot point by point

    I'm sorry but I won't debug your code for you, you have to do that.
    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.


  26. #20
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: display a plot point by point

    No , I'm sorry ,
    i show the code cuz i suppose there is a simple mistake i can't see it as a Qt beginner .
    Last edited by oswalidos; 11th March 2009 at 20:20.

Similar Threads

  1. Replies: 3
    Last Post: 20th April 2006, 12:21

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.