V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wbing
V2EX  ›  问与答

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

  •  
  •   wbing · 2018-06-13 09:11:05 +08:00 · 903 次点击
    这是一个创建于 2137 天前的主题,其中的信息可能已经有所发展或是发生改变。
    板子不支持 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 条回复    2018-06-13 18:05:31 +08:00
    nybux
        1
    nybux  
       2018-06-13 16:52:08 +08:00
    你换 repaint 试试
    wbing
        2
    wbing  
    OP
       2018-06-13 17:34:53 +08:00
    @nybux 试过了,repaint 会把父窗口也刷白了
    nybux
        3
    nybux  
       2018-06-13 18:05:31 +08:00
    那设置个无效区域呢?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5661 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 01:49 · PVG 09:49 · LAX 18:49 · JFK 21:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.