我模拟了诸如质量弹簧减振器之类的动力装置。QT实时解决运动方程并显示输出。我想使用一个Qapplication对象,以“实时”显示数据和输出。我不知道我应该为此目的在连接命令中放入“信号类型”“(我认为答案可能是QGraphicsRectItem类的方法之一-这里发生的变化是RectItem Position)。多谢您的回覆!主要类别是:
#include "onboard.h"
Pltaform::Pltaform()
{
GraphicMass = new Motion();
iTH = new QThread;
}
void OnBoard::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 OnBoard::DisplayQGraphic()
{
GraphicMass->pos_x = states(0);
GraphicMass->pos_y = states(1);
// connect
GraphicMass->moveToThread(iTH);
connect(GraphicMass,SIGNAL(?????),this,SLOT(move()));
iTH->start();
}
void OnBoard::move()
{
setPos(x()+GraphicMass->pos_x,y()-GraphicMass>pos_y);
}
Motion类为:
#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;
QGraphichsRectItem
及其任何父类没有任何已实现的信号。因此,您需要通过将Qt
类继承到自己的新类中来发出自己的信号,以供使用。我不确定如何执行此操作,因为我看不到代码,但是我可以预测您需要重新实现setRect()
或实现移动操作的任何其他函数,只需调用super函数并发出信号在其末尾。