将QImage转换为QML [英] QImage into QML

查看:170
本文介绍了将QImage转换为QML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序通过网络接收JPEG实时流(每秒16帧).直播应使用QML显示.接收部分用C ++编写,所有UI均使用QML编写.

My application receives a live-stream of JPEGs over network (16 frames per second). The live-stream should be displayed using QML. The receiving part is written in C++, all the UI is written using QML.

如何将图像数据放入QML窗口?我已经研究了如何显示QImage,但是还没有找到解决方案.

How do I get the image data into the QML window? I have looked around how to get a QImage displayed, but I did not find a solution yet.

实施QDeclarativeImageProvider并使用其他名称一次又一次刷新图像源似乎是唯一的解决方案,请参见

Implementing QDeclarativeImageProvider and refreshing the source of the image over and over again using a different name seems to be the only solution, see http://qt-project.org/doc/qt-4.8/qdeclarativeimageprovider.html.

推荐答案

是的,不幸的是,Image元素缺少update()方法(强制重置). 设置完全相同的源URL不会触发更新.

Yes, unfortunately the Image element is missing an update() method (to forcibly reset it). Setting the very same source URL will not trigger an update.

您可以使用类似方法来解决此问题:

You can use something like this as a workaround:

Image {
    source: "image://yourImageProvider/something"
    cache: false
    function reload() {
        var oldSource = source;
        source = "";
        source = oldSource;
    }
}

(或仅在两个URL之间切换,这些URL具有相同的提供程序名称,但路径不同...)

(Or just switch between two URLS, with the same provider name, but different paths...)

您还应该推送将收到的JPEG推送到QML层.收到新图像后,您应该从暴露给QML引擎的某个对象的C ++一侧发出信号,并将该信号连接到该reload()函数. Connections元素会帮助您.

You should also push those JPEGs you receive to the QML layer. Once you receive a new image, you should emit a signal from C++'s side from some object exposed to the QML engine, and connect that signal to that reload() function. The Connections element will help you there.

Connections {
    target: myC++ObjectExposedToTheQMLEngine
    onNewFrameReceived: image.reload(); 
}

这篇关于将QImage转换为QML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆