Results 1 to 20 of 59

Thread: How i can plot result in my GUI ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: plot during execution

    your code can't work. why do you clear the points-vector in each loop? I already gave you the solution how to fix that...

    remember:
    Qt Code:
    1. QPolygonF polygon;
    2. for(unsigned int i=0; i<10; i++)
    3. polygon << function();
    4.  
    5. curve->setSamples(polygon);
    To copy to clipboard, switch view to plain text mode 

    and you don't need to call "myplot->show()" in plotValuesFromFunction, it's sufficient to do that once in the constructor.

    PS: you already opened one thread for this topic. it's very bad style to create a second thread only because nobody answers in your first thread.

  2. The following user says thank you to FelixB for this useful post:

    21did21 (10th June 2011)

  3. #2
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    i clear previous point because i want:
    => run calcul and get 1point
    => plot this point
    => run calcul and get 1 point
    => plot this point
    ....
    for each points

    and i don't want a polynom, i just want a plot with only points. (Dots style; i think )

    ps: I made this post because the other start to be very rough and can not distinguish what I was looking for
    Last edited by 21did21; 10th June 2011 at 09:56.

  4. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: plot during execution

    it makes no difference whether you use a polygon or a vector. that has no effect on the style. you can set the style by using "QwtPlotCurve::setStyle (CurveStyle style)".

    you plot exactly one point after each calculation. the previously calculated (and plotted) points will be deleted. is that really what you want? or do you want to keep all points in the plot?

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

    21did21 (10th June 2011)

  6. #4
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    Quote Originally Posted by FelixB View Post
    it makes no difference whether you use a polygon or a vector. that has no effect on the style. you can set the style by using "QwtPlotCurve::setStyle (CurveStyle style)".
    ok . thank you

    Quote Originally Posted by FelixB View Post
    you plot exactly one point after each calculation. the previously calculated (and plotted) points will be deleted. is that really what you want? or do you want to keep all points in the plot?
    ok! i understand why i must not clear the vector!
    => yes i want to plot one point and keep the previous

    thank you for yur help

    => i try, and i will keep informed

    EDIT:
    i think now i understand the mistake, i try it and i will keep you informed
    Last edited by 21did21; 10th June 2011 at 14:13.

  7. #5
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    i do something better, but it style don't work....

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "MyMainWindow.h"
    3. #include <QGridLayout>
    4. #include "RunSimulation.h"
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. MyMainWindow fenetre;
    9. fenetre.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    MyMainWindow
    Qt Code:
    1. -------------------.h-----------------
    2. #ifndef MYMAINWINDOW_H
    3. #define MYMAINWINDOW_H
    4. #include <QApplication>
    5. #include <QWidget>
    6. #include <QPushButton>
    7. #include <QMessageBox>
    8. #include <qwt_plot_curve.h>
    9. #include <qwt_plot.h>
    10. class MyMainWindow : public QWidget
    11. {
    12. Q_OBJECT
    13. public:
    14. explicit MyMainWindow(QWidget* parent = 0);
    15. void plotValuesFromFunction(std::vector< std::vector<double> >);
    16. public slots:
    17. void myRunSlot();
    18. private:
    19. QPushButton *BUTTONRun;
    20. QPushButton *BUTTONQuit;
    21. QPushButton *BUTTONAbout;
    22. QPushButton *BUTTONContact;
    23. QwtPlot *myPlot1;
    24. QwtPlot *myPlot2;
    25. QwtPlotCurve myCurve1;
    26. QwtPlotCurve myCurve2;
    27. };
    28. #endif // MYMAINWINDOW_H
    29. --------------.cpp--------------------------
    30. #include "MyMainWindow.h"
    31. #include <QGridLayout>
    32. #include <QHBoxLayout>
    33. #include <qwt_plot.h>
    34. #include <qwt_plot_curve.h>
    35. #include <qwt_symbol.h> //for symbol in the curve
    36. #include "RunSimulation.h"
    37. #include <vector>
    38. using namespace std;
    39. MyMainWindow::MyMainWindow(QWidget* parent) : QWidget(parent)
    40. {
    41. QGridLayout* mainLayout = new QGridLayout();
    42. setLayout(mainLayout);
    43. myPlot1 = new QwtPlot();
    44. myPlot2 = new QwtPlot();
    45. myPlot1->setMinimumSize(200, 100);
    46. myPlot2->setMinimumSize(200, 100);
    47. QWidget* buttonWidget = new QWidget();
    48. QGridLayout* buttonLayout = new QGridLayout();
    49. BUTTONRun = new QPushButton("RUN");
    50. BUTTONQuit = new QPushButton("STOP");
    51. BUTTONAbout = new QPushButton("About");
    52. BUTTONContact = new QPushButton("Contact");
    53. buttonLayout->addWidget(BUTTONRun ,0,1);
    54. buttonLayout->addWidget(BUTTONQuit ,1,1);
    55. buttonLayout->addWidget(BUTTONAbout ,2,1);
    56. buttonLayout->addWidget(BUTTONContact,3,1);
    57. buttonWidget->setLayout(buttonLayout);
    58. mainLayout->addWidget(myPlot1 ,0,0,1,1);
    59. mainLayout->addWidget(myPlot2 ,0,1,1,1);
    60. mainLayout->addWidget(buttonWidget ,0,3,1,1);
    61. myCurve1.attach(myPlot1);
    62. myCurve2.attach(myPlot2);
    63. QObject::connect(BUTTONQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
    64. QObject::connect(BUTTONAbout, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
    65. QObject::connect(BUTTONRun, SIGNAL(clicked()), this, SLOT(myRunSlot()));
    66. }
    67. void MyMainWindow::plotValuesFromFunction(vector< vector<double> > Points_OneXtwoY)
    68. {
    69. int sizeOfVector=Points_OneXtwoY[0].size();
    70. QVector<double> x(sizeOfVector);
    71. QVector<double> y(sizeOfVector);
    72. for (int z=0;z<sizeOfVector;z++)
    73. {
    74. x.append( Points_OneXtwoY[0][z] );
    75. y.append( Points_OneXtwoY[1][z] );
    76. }
    77. myPlot1->replot();
    78. myPlot2->replot();
    79. myCurve1.setSamples(x.data(),y.data(),x.size());
    80. myCurve2.setSamples(x.data(),y.data(),x.size());
    81. myPlot1->show();
    82. myPlot2->show();
    83. }
    84. void MyMainWindow::myRunSlot()
    85. {
    86. RunSimulation(this); //this
    87. }
    To copy to clipboard, switch view to plain text mode 
    RunSimulation
    Qt Code:
    1. ------------------.h---------------------
    2. #ifndef RUNSIMULATION_H
    3. #define RUNSIMULATION_H
    4. #include "MyMainWindow.h"
    5. void RunSimulation(MyMainWindow *fenetre);
    6. #endif // RUNSIMULATION_H
    7. ------------------.cpp-------------------
    8. #include <QApplication>
    9. #include <qwt_plot.h>
    10. #include <qwt_plot_curve.h>
    11. #include <vector>
    12. #include "function.h"
    13. #include "RunSimulation.h"
    14. #include "MyMainWindow.h"
    15. using namespace std;
    16. void RunSimulation(MyMainWindow *fenetre)
    17. {
    18. vector<double> coordX;
    19. vector<double> coordY;
    20. vector< vector<double> >coordX_Y;
    21. coordX_Y.push_back(coordX);
    22. coordX_Y.push_back(coordY);
    23. vector<double> points;
    24. for (int i=1;i<10;i++)
    25. {
    26. points.clear();
    27. points=function();
    28. coordX_Y[0].push_back(points[0]);
    29. coordX_Y[1].push_back(points[1]);
    30. fenetre->plotValuesFromFunction(coordX_Y);
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 
    function
    Qt Code:
    1. ----------------.h------------------
    2. #ifndef FUNCTION_HPP
    3. #define FUNCTION_HPP
    4. std::vector<double> function();
    5. #endif // FUNCTION_HPP
    6. -----------------.cpp---------------
    7. #include <vector>
    8. #include <ctime> // to generate random point
    9. #include <cstdlib> // to generate random point
    10. #include "function.h"
    11. #include "windows.h"
    12. using namespace std;
    13. vector<double> function()
    14. {
    15. vector<double> ppoints;
    16. ppoints.clear();
    17. //----------------
    18. srand(time(0));
    19. Sleep(1000);
    20. //----------------
    21. ppoints.push_back(rand() % 1800);
    22. ppoints.push_back(rand() % 500);
    23. return ppoints;
    24. }
    To copy to clipboard, switch view to plain text mode 

    it still don't plot during the execution

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

    Default Re: plot during execution

    Plotting a point doesn't cause an immediate repaint of the user interface. Events need to be processed so that Qt can ask your widget to repaint itself. Without that your loop runs continously and you will only see the final result. Please read the docs or search the forum for event processing and redrawing issues, it's a frequent problem.
    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. #7
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    Quote Originally Posted by wysota View Post
    Plotting a point doesn't cause an immediate repaint of the user interface. Events need to be processed so that Qt can ask your widget to repaint itself. Without that your loop runs continously and you will only see the final result. Please read the docs or search the forum for event processing and redrawing issues, it's a frequent problem.
    thank you for this answer, but sorry i don't understand that you speak about.

    can you reformulate please because i am not an english people.

    i have two difficulty:
    => Qwt and the english language

    EDIT:

    if i understand, you say:
    => my programm is good but Qt have not time to replot correctly, so i just can see the final result ?
    => have you link which speaks about this to understand how i can resolve my problem?
    Last edited by 21did21; 10th June 2011 at 19:38.

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

    Default Re: plot during execution

    Read about Qt's event processing in the documentation. As part of your lecture, have a look at the docs for QWidget::update().
    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:

    21did21 (11th June 2011)

  12. #9
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    i have add before this line:

    Qt Code:
    1. myCurve1.setSamples(x.data(),y.data(),x.size());
    To copy to clipboard, switch view to plain text mode 

    of my plot method the line:

    Qt Code:
    1. update();
    To copy to clipboard, switch view to plain text mode 

    but it don't change something....

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

    Default Re: plot during execution

    Why would it change anything? Did you read the documentation for the method carefully? Did you also read any other paragraphs on event processing in 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.


  14. #11
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    yes but i don't understand very well the content...

    it's too difficult for me, i don't understand why qt don't work correctly for this applciation

    => when i see the example from qwt then i see that ploting work during execution (see for example oscillopscope example; why this example work and not mine?)

    EDIT:

    i think it can work if i use Qwt function like replot() or restore... or something like this no?

    a friend use C++ builder and it can do this easily, so why i can't with Qwt? i think it's easy command but i don't find the correct command and i don't understand where i have to put tjis command....
    Last edited by 21did21; 10th June 2011 at 22:06.

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

    Default Re: plot during execution

    Quote Originally Posted by 21did21 View Post
    yes but i don't understand very well the content...

    it's too difficult for me, i don't understand why qt don't work correctly for this applciation
    Well, I'm sorry, I can't teach you to read with understanding. The docs for update() clearly state what your problem is. Your problem is very easy to solve but there is no point in giving you a ready solution if you wouldn't understand it. I can also point you to this article: [wiki]Keeping the GUI Responsive[/wiki] and suggest to take the "step by step" approach.

    a friend use C++ builder and it can do this easily, so why i can't with Qwt?
    Because Qt is event-driven and the other framework is not. Thanks to that Qt is fast and your friend's framework is not.

    i think it's easy command but i don't find the correct command and i don't understand where i have to put tjis command....
    What command?
    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. QRegExp - get only last result
    By kabanek in forum Newbie
    Replies: 2
    Last Post: 3rd November 2010, 22:17
  2. How to display result
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 08:39
  3. QSqlQuery return result
    By arpspatel in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2010, 07:55
  4. Result of DBUS call
    By conexion2000 in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2009, 08:34
  5. Replies: 7
    Last Post: 22nd September 2008, 22:05

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.