【问题标题】:Asynchronously update multiple QQuickPaintedItem on QML在 QML 上异步更新多个 QQuickPaintedItem
【发布时间】:2014-10-02 19:02:48
【问题描述】:

我正在尝试使用继承自 QQuickPaintedItem 的类来显示使用 openCV 捕获的视频帧。

在这个类中,有一个名为 queryFrame() 的槽,它通过以下方式连接到 QTimer timout (40ms):

connect(m_timer, SIGNAL(timeout()), this, SLOT(queryFrame()));

queryFrame() 代码:

void CVCamScreen::queryFrame()
{
    if(!m_url.isEmpty()){
        if( !m_capture->isOpened() ) {
            m_capture->open( m_url.toStdString() );
        }

        cv::Mat frame;
        m_capture->read( frame );

        m_qImage = ipl2Qimg(new IplImage(frame));

        update();

        emit frameChanged();
    }
}

每次调用 queryFrame() 都应该更新视图。它正在这样做,但它不是异步工作的。

我应该如何让每个 CVCamScreen 以独立的方式自行更新?

呈现 CamScreens 的 QML 代码:

Repeater {
    model: 8

    CVCamScreen {
        Layout.fillWidth: true
        Layout.fillHeight: true

        url: Controller.urlCanal(index + 1)

        CustomBorder {
            commonBorder: true
            color: "#228e14"
            commonBorderWidth: 3
        }

        onUrlChanged: {
            start(); // starts the timer when the URL changes.
        }
    }
}

【问题讨论】:

    标签: c++ qt opencv qml qquickitem


    【解决方案1】:

    您的问题是所有CVCamScreen 对象都在同一个线程中。因此,定时器事件按顺序传递给它们。我建议将实际读取从设备和ipl2Qimg() 的东西移到后台线程中,当数据准备好并且应该调用update() 时,它只会通知CVCamScreen

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-18
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多