Page 3 of 3 FirstFirst 123
Results 41 to 59 of 59

Thread: How i can plot result in my GUI ?

  1. #41
    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 15:13.

  2. #42
    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

  3. #43
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: 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.


  4. #44
    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 20:38.

  5. #45
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: 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.


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

    21did21 (11th June 2011)

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

  8. #47
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: 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.


  9. #48
    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 23:06.

  10. #49
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: 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.


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

    Default Re: plot during execution

    Quote Originally Posted by wysota View Post
    Well, I'm sorry, I can't teach you to read with understanding. Your problem is very easy to solve but there is no point in giving you a ready solution if you wouldn't understand it.
    ok, i have difficulty, but if you do not want to help me by providing some part of code, so don't reply at this thread ?

  12. #51
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: plot during execution

    If you expect that someone is going to do your job for you then that's not how things work on this forum. Do your homework and read the docs.
    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.


  13. #52
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    i think i have find the solution!!!

    => i have to use the function "repaint()" :

    i am very happy !

    wysota:
    please don't pollute my thread.
    thank you

    see you

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

    Default Re: How i can plot result in my GUI ?

    my problem i solved.

    thank you everybody for your help, it's very kind

  15. #54
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: plot during execution

    Quote Originally Posted by 21did21 View Post
    i think i have find the solution!!!

    => i have to use the function "repaint()" :

    i am very happy !
    That's the worst solution you might have taken.

    wysota:
    please don't pollute my thread.
    Then don't spam the board with multiple threads (three threads merged).
    Last edited by wysota; 11th June 2011 at 01:37.
    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.


  16. #55
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    Quote Originally Posted by wysota View Post
    That's the worst solution you might have taken.
    i haven't an infini time to solve my problem so i prefere this solution rather than nothing.

    Quote Originally Posted by wysota View Post
    Then don't spam the board with multiple threads (three threads merged).
    I made several post because the other start to be very rough and can not distinguish what I was looking for.

    ps: you can close this thread it is solve

    thank you to everyone who took the time to help me

  17. #56
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: plot during execution

    Quote Originally Posted by 21did21 View Post
    i haven't an infini time to solve my problem so i prefere this solution rather than nothing.
    Sure. Why learn if you can just sit and wait until the answer falls down from the sky.

    I made several post because the other start to be very rough and can not distinguish what I was looking for.
    If you want others to help you then keep a reference to what was already said in the subject. Otherwise you'll be getting three similar responses in three different threads wasting time of three people.
    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.


  18. #57
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot during execution

    Quote Originally Posted by wysota View Post
    If you want others to help you then keep a reference to what was already said in the subject. Otherwise you'll be getting three similar responses in three different threads wasting time of three people.
    it's true excuse me

    Quote Originally Posted by wysota View Post
    Sure. Why learn if you can just sit and wait until the answer falls down from the sky.
    why you say this? i have find alone the solution for repaint?
    (and a forum is to have some help no??)

    EDIT:
    quand you close this thread i don't want continue this poor discussion

  19. #58
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: plot during execution

    Quote Originally Posted by 21did21 View Post
    why you say this? i have find alone the solution for repaint?
    Your solution is like driving a car by pushing it with your hands instead of starting the engine and hopping into the driver's seat. Despite being directed to do that several times.

    (and a forum is to have some help no??)
    Help -- yes. Outsourcing -- no.
    Last edited by wysota; 18th June 2011 at 01:55.
    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. #59
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    21did21: I think your problem is that you do not understand enough about C++ to get started. There are so many errors in your code that it is difficult for anyone here to help you (except to write the code for you). We are trying to be helpful, but we can't teach you C++.

    Is there someone you know who has some C++ knowledge who speaks your native language? It would be much better for you to sit with that person and ask them for help instead of trying to solve it here.

Similar Threads

  1. QRegExp - get only last result
    By kabanek in forum Newbie
    Replies: 2
    Last Post: 3rd November 2010, 23:17
  2. How to display result
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 09:39
  3. QSqlQuery return result
    By arpspatel in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2010, 08:55
  4. Result of DBUS call
    By conexion2000 in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2009, 09:34
  5. Replies: 7
    Last Post: 22nd September 2008, 23: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.