0

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". I don't know What should I put the "signal type" " in connect command" for this aim.(The answer in my opinion will probably be one of the method of QGraphicsRectItem class - Something is changing here is RectItem Position).

the main class is:

#include "QTcpSocket"
#include "QHostAddress"
#include "QObject"
#include "QThread"

Pltaform::Pltaform()
{
   GraphicMass = new Motion();
   iTH = new QThread;
}

void Pltaform::run()
{

isRunning = true;
while (isRunning)
{

    switch (&message)
    {
    case 1:
        getWorldData();
        break;

    case 2:
        calculateControls();
        DisplayQGraphic();
        sendPlatformData();
        break;

    case 3:
        isRunning = false;
        cout << "Simulation Finished." << endl;
        break;


 void Pltaform::DisplayQGraphic()
 {
GraphicMass->pos_x = states(0);
GraphicMass->pos_y = states(1);

 // connect
 GraphicMass->moveToThread(iTH);

 connect(GraphicMass,SIGNAL(?????),this,SLOT(move()));

 iTH->start();
}

void Pltaform::move()
{
setPos(x()+GraphicMass->pos_x,y()-GraphicMass>pos_y);
}

and the Motion class is:

#include "QGraphicsScene"
#include "QGraphicsView"
#include "QGraphicsRectItem"
#include "QObject"

 Motion::Motion()
 {
 // create an item to put into the scene
 setRect(0,0,20,30);
 setPos(x(),y());

 pos_x = 0;
 pos_y = 0;}
esmaeil
  • 1
  • 2
  • ***What signal should I put in the connect command when i solving the dynamic equation in “Real time”؟** I am unsure how we are possibly going to know that. We don't have your code. You most likely need to produce a [mcve] – drescherjm May 21 '20 at 15:54

1 Answers1

0

QGraphichsRectItem and any of its parent classes don't have any implemented signals. So, you need to emit your own signal(s) by inheriting Qt class into your own new class, that you'll use it. I'm not sure how this will be done because I couldn't see the code, but I may predict that you need to reimplement setRect() or any other function that implements the moving operation, just call the super function and emit the signal at its end.

Mohammed Deifallah
  • 1,290
  • 1
  • 10
  • 25