• 5005阅读
  • 2回复

qt 动态绘制路径出现BUG,路过的大神帮忙解决哈 [复制链接]

上一主题 下一主题
离线robotuisky
 

只看楼主 倒序阅读 楼主  发表于: 2014-05-16

我要实现的功能是在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);
}
  
离线robotuisky

只看该作者 1楼 发表于: 2014-05-16
怎么没人顶呀,高手帮忙进来看下问题出错在那嘛
离线robotuisky

只看该作者 2楼 发表于: 2014-05-16
问题解决了,是下位机发上来的数据 没加锁。。。。。。。。。。
快速回复
限100 字节
 
上一个 下一个