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
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: plot a curve during compilation

    I'm too bad I did not understand "Qpolygon" so I tried something else:

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include <qwt_plot.h>
    3. #include <qwt_plot_curve.h>
    4. #include <vector>
    5. #include "function.hpp"
    6. using namespace std;
    7. int main(int argc, char** argv)
    8. {
    9. QApplication app(argc,argv);
    10. QwtPlot myPlot;
    11. QwtPlotCurve myCurve;
    12. myCurve.attach(&myPlot);
    13. for (int i=1;i<10;i++)
    14. {
    15. vector<double> points;
    16. points=function();
    17. QVector<double> x(1);
    18. QVector<double> y(1);
    19. x.append( points[0]);
    20. y.append( points[1]);
    21. }
    22. myCurve.setSamples(x.data(),y.data(),x.size());
    23. myPlot.replot();
    24. myPlot.show();
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 
    function.cpp
    Qt Code:
    1. #include <vector>
    2. #include <ctime> // to generate random point
    3. #include <cstdlib> // to generate random point
    4. #include "function.hpp"
    5. using namespace std;
    6. vector<double> function()
    7. {
    8. vector<double> points;
    9. srand(time(0));
    10. points.clear();
    11. Sleep(5000);
    12. points.push_back(rand() % 1800);
    13. points.push_back(rand() % 500);
    14. return points;
    15. }
    To copy to clipboard, switch view to plain text mode 
    function.hpp
    Qt Code:
    1. #ifndef FUNCTION_HPP
    2. #define FUNCTION_HPP
    3. std::vector<double> function();
    4. #endif // FUNCTION_HPP
    To copy to clipboard, switch view to plain text mode 

    but this code say:

    X and Y are not declared in this scope, but i have declared this values???

    can you help me
    i bloc with Qwt until 3week just to plot a plot with some points

  2. #2
    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 a curve during compilation

    you need some more c++-knowledge, your problems are not qwt-related. the vectors x and y are declared within scope of the loop. you can't access them when you left the loop. have you ever filled an array with a loop?

    in "fonction", you don't need the call "points.clear()" since the vector is empty when you create it. is there any reason for the "sleep(5000)"?

    ok, I'll help you with some code. I suggest to get back to QPolygonF. Then you can return a QPointF in "fonction()" directly. This is more intuitive and you can forget all the QVector stuff you don't need... I'll give you the modified loop and let you adapt "fonction()" by yourself. I'll help you when you can't manage that.

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

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

    21did21 (1st June 2011)

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

    Default Re: plot a curve during compilation

    Quote Originally Posted by FelixB View Post
    is there any reason for the "sleep(5000)"?
    because my real code take a lot of time to calcul my values and here i want to simul this waiting time

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