QImage into QML

[亡魂溺海] 提交于 2019-12-08 05:42:25

问题


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.

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.

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.


回答1:


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;
    }
}

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

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(); 
}


来源:https://stackoverflow.com/questions/17728337/qimage-into-qml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!