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:
// RunSimulation.h
Q_OBJECT
public:
void sendData( const vector<double>& data ){
emit newData(data);
}
static Notifier& instance(){
static Notifier inst;
return inst;
}
signals:
void newData( const vector<double>& data );
};
//RunSimulation.cpp
void RunSimulation()
{
vector<double> points;
for (int i=1;i<10;i++)
{
points.clear();
points=function();
Notifier::instance().sendData(points);
}
}
// and in main:
void MyMainWindow::myRunSlot()
{
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
RunSimulation();
}
// RunSimulation.h
class Notifier : public QObject{
Q_OBJECT
public:
Notifier( QObject * parent = NULL ) : QObject(parent){}
void sendData( const vector<double>& data ){
emit newData(data);
}
static Notifier& instance(){
static Notifier inst;
return inst;
}
signals:
void newData( const vector<double>& data );
};
//RunSimulation.cpp
void RunSimulation()
{
vector<double> points;
for (int i=1;i<10;i++)
{
points.clear();
points=function();
Notifier::instance().sendData(points);
}
}
// and in main:
void MyMainWindow::myRunSlot()
{
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
RunSimulation();
}
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:
//
#include "MyMainWindow.h"
void RunSimulation( MyMainWindow * mainWindow ){
vector<double> points;
for (int i=1;i<10;i++)
{
points.clear();
points=function();
mainWindow->plotData(points);
}
}
// main:
void MyMainWindow::myRunSlot()
{
RunSimulation(this);
}
//
#include "MyMainWindow.h"
void RunSimulation( MyMainWindow * mainWindow ){
vector<double> points;
for (int i=1;i<10;i++)
{
points.clear();
points=function();
mainWindow->plotData(points);
}
}
// main:
void MyMainWindow::myRunSlot()
{
RunSimulation(this);
}
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.
Bookmarks