I simulated a dynamical device like mass spring damper.the QT Solves the equation of motion in Real Time and displays the output. I want to use an Qapplication object,to display Data and the outputs in "Real time". whole problem and display output is inside a loop.Everything is going well, but when the program reaches to command return a.exec()
for display output,the GUI window Has come up and remain in the firest iteration." I expect don't gets stuck there and At each loop the program runs And at the end of loop update the GUI window in "Real time".
here is my code:
#include "QtWidgets/QApplication"
#include "QtWidgets/QGraphicsScene"
#include "QObject"
#include "QTimer"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Motion* ball = new Motion();
// create a scene
QGraphicsScene * scene = new QGraphicsScene();
QGraphicsRectItem* rect = new QGraphicsRectItem();
//show the view
view->show();
The Loop I talked about that.
for (int i = 0; i<int(j); i++)
{
Sleeper::msleep(50);
double t = time->getTime() + i*0.05;
states2 = world.openLoopSys;
for (int i=0; i<12; i++)
{
states1(i) = states2(i);
}
ball->run();
return a.exec(); // gets stuck there !!!
}
The Motion class is:
#include "motion.h"
Motion::Motion()
{
// create an item to put into the scene
setRect(0,0,20,30);
setPos(x(),y());
pos_x = 0;
pos_y = 0;
}
void Motion::run()
{
// connect
QTimer * timer = new QTimer();
connect(this,SIGNAL(timeout()),this,SLOT(move()));
timer->start(50);
}
void Motion::move()
{
setPos(x(),y()-5);
// setPos(0.01*pos_x,-0.01*pos_y);
}
How can I solve this problem?