benson458
V2EX  ›  问与答

在 arm 开发板上面, qt4.8.6,通过 usb 取流,然后通过一个 label 去渲染视频,程序跑久了后, update 信号不会触发 paintEvent,是怎么回事?

  •  
  •   benson458 · Jun 13, 2018 · 1295 views
    This topic created in 2919 days ago, the information mentioned may be changed or developed.
    板子不支持 opengles,所以就用 label 去贴了,代码如下

    ··· c++

    void QVideoView::PaintOneFrame(QImage imge)
    {

    m_mutex.lock();
    wb_Image = imge.copy();
    m_mutex.unlock();

    update(); //调用 update 将执行 paintEvent 函数
    }
    ···

    //重写 paintEvent 事件
    void QVideoView::paintEvent(QPaintEvent *)
    {
    QTime time;
    time.start(); //开始计时,以 ms 为单位
    QPainter painter;
    painter.begin(this);
    m_mutex.lock();
    if (wb_Image.size().width() <= 0)
    {
    m_mutex.unlock();
    return;
    }
    ///将图像按比例缩放成和窗口一样大小
    QImage img = wb_Image.scaled(this->size(),Qt::IgnoreAspectRatio);
    m_mutex.unlock();
    int x = this->width() - img.width();
    int y = this->height() - img.height();

    painter.drawImage(QPoint(x,y),img); //画出图像
    painter.end();

    }

    连续跑个五六个小时就会出现了,尝试过用 QTimer 去定时调用 update(),但也是一样的情况,有没人能解答下的?
    3 replies    2018-06-13 18:05:31 +08:00
    nybux
        1
    nybux  
       Jun 13, 2018
    你换 repaint 试试
    benson458
        2
    benson458  
    OP
       Jun 13, 2018
    @nybux 试过了,repaint 会把父窗口也刷白了
    nybux
        3
    nybux  
       Jun 13, 2018
    那设置个无效区域呢?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1138 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:11 · PVG 07:11 · LAX 16:11 · JFK 19:11
    ♥ Do have faith in what you're doing.