Results 1 to 20 of 59

Thread: How i can plot result in my GUI ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

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

    Ok, but you'll need to make some changes to the RunSimulation code anyway.
    Another way, create an instance of notifier class, based on QObject, and use it to send signals with new data from RunSimulation method, something like this:
    Qt Code:
    1. // RunSimulation.h
    2.  
    3. class Notifier : public QObject{
    4. Q_OBJECT
    5. public:
    6. Notifier( QObject * parent = NULL ) : QObject(parent){}
    7. void sendData( const vector<double>& data ){
    8. emit newData(data);
    9. }
    10.  
    11. static Notifier& instance(){
    12. static Notifier inst;
    13. return inst;
    14. }
    15.  
    16. signals:
    17. void newData( const vector<double>& data );
    18. };
    19.  
    20. //RunSimulation.cpp
    21.  
    22. void RunSimulation()
    23. {
    24. vector<double> points;
    25. for (int i=1;i<10;i++)
    26. {
    27. points.clear();
    28. points=function();
    29. Notifier::instance().sendData(points);
    30. }
    31. }
    32.  
    33. // and in main:
    34. void MyMainWindow::myRunSlot()
    35. {
    36. connect( &Notifier::instance(), SIGNAL(newData(const vector<double>&)), this, SLOT(plotData(const vector<double>&)) ); // you'll need to create this slot to plot incoming data
    37. RunSimulation();
    38. }
    To copy to clipboard, switch view to plain text mode 
    You may not like the idea of a kind of singleton, but it's only an example of how you can connect your simulation method with main gui. More brute way could be to simply pass this pointer to RunSimulation method:
    Qt Code:
    1. //
    2. #include "MyMainWindow.h"
    3.  
    4. void RunSimulation( MyMainWindow * mainWindow ){
    5. vector<double> points;
    6. for (int i=1;i<10;i++)
    7. {
    8. points.clear();
    9. points=function();
    10. mainWindow->plotData(points);
    11. }
    12. }
    13. // main:
    14. void MyMainWindow::myRunSlot()
    15. {
    16. RunSimulation(this);
    17. }
    To copy to clipboard, switch view to plain text mode 
    Again, you won't escape changing the RunSimulation method, because all the data you compute there is local, you need to expose this data somehow.
    Another way could be to take advantage of Qt event processing - create a subclass of QEvent and send it with QCoreApplication::sendEvent() to mainWindow.

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

    21did21 (3rd June 2011)

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.