Results 1 to 20 of 33

Thread: display a plot point by point

Hybrid View

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

    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 .

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    oswalidos (10th March 2009)

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

    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

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    oswalidos (10th March 2009)

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

    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 21:52.

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    oswalidos (10th March 2009)

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

    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

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    oswalidos (10th March 2009)

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

    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 .

  14. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    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 19:20.

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

    Default Re: display a plot point by point

    I suggest you improve your C++ skills a bit before taking on Qt.
    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. #13
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Platforms
    Windows
    Thanks
    12

    Default Re: display a plot point by point

    hello ,
    i realized that my problem have no relation with my code.
    in fact a simple application like "simple_plot" works normally when i create a new project ,move sources and modify *.pro ,but when i do the same for other example like "real_time plot" and try to build it , i have the same problem with a warning(exited with code -1073741819 ,no errors ,warning: #warning better use QwtData) and degugger don't works anymore .
    so it's a configuration problem .
    i downloaded qwt 5.2 from svn but it's the same problem !

    -each time i want to run my application from Qt console or from Qt creator i have to add qwtd5.dll to debug folder,everybody do that ?
    -i want to buid Qt in debug mode ,it takes time ,finally it generate errors related with visual studio 2008
    -why to build Qt in debug mode?
    -mingw's gdb isn't enough to debug Qt applications since we're using Qt's sources ?
    -what about .pri and .prf ? should i modify one ?
    -why debugger under Qt creator works(just for an application without macro Q_OBJECT) even if Qt isn't buit in debug mode ?

    please look up my .pro
    if my questions proves that i'm lost ,some links will be enough to stop annoying you .

    regards
    Last edited by oswalidos; 11th March 2009 at 19:55.

Similar Threads

  1. Replies: 3
    Last Post: 20th April 2006, 11: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
  •  
Qt is a trademark of The Qt Company.