我要实现的功能是在
View显示,scene类中实时根据下位机发来的
数据修改路径
代码架构 view类中直接调用 setscene(&scene)来绘制
myscen类中调用虚函数drawForeground来绘制动态路径
程序正常运行几分钟后就出现BUG

正常的时候如下图,蓝色的是绘制出来的路径实时变化的

代码如下:
C/C++ code
///或许下位机发来的数据 间隔20毫秒
void myscen::getPath( ArNetPacket * packet )
{
int numPoints;
static bool firstpoint=false;
numPoints=packet->bufToByte2();
if (numPoints!=0)
{
mPath = QPainterPath();
firstpoint=true;
for (int num=0;num<numPoints;num++)
{
int pathx=packet->bufToByte4();
int pathy=packet->bufToByte4();
if (firstpoint)
{
//mPath.moveTo(mPath.currentPosition());
mPath.moveTo(QPointF(pathx,pathy));
firstpoint=false;
}
else
{
mPath.lineTo(QPointF(pathx,pathy));
}
}
mPath.currentPosition();
// myupdata=true;
}
}
/// 把绘制的mpath画的画布上
void myscen::drawForeground(
QPainter *painter, const QRectF &rect)
{
if (!mPath.isEmpty())
{
painter->save();
mpathpen.setCosmetic(true);
mpathpen.setColor(Qt::blue);
mpathpen.setWidth(3);
painter->setPen(mpathpen);
painter->drawPath(mPath);
//painter->strokePath(mPath,mpathpen);
painter->restore();
//this->invalidate(rect ,QGraphicsScene::ForegroundLayer);
}
//painter=new QPainter();
//this->update(rect);
//this->invalidate(rect ,QGraphicsScene::ForegroundLayer);
}