Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QtQuick / QML / Display MJPEG Image Stream - QImages - from C++
werispaul last edited by
Hi Qt community,
i'm locking for a convenient way to display QImages in a QtQuick / QML Scene. Images are provided by a MJPEG Stream received via a C++ module.
I've identified several ways to do this so far, but am unsure what the best solution, in sense of performance, would be.
- Using QImageProvider, disabling cache and emitting an update Signal from C++ on image change
- Re-implement a QQuickItem using UpdatePaintNodeData() ( drawing via QSGGeometry )
- Re-implement a QQuickPaintedItem using paint()
Thanks in advance for sharing your experience.
I'm afraid my answer will not be terribly reassuring: all 3 ways are correct and valid :)
I think the QImageProvider is the most "official" way to do it, and it may help in other places, too (all functionalities of QML Image component will still work, while when reimplementing QQItem you need to provide all the functionality yourself).
werispaul last edited by
A not completely unexpected answer. ;)
I decided to use the ImageProvider and it seems to work fine, at least with a 40ms update rate. Currently I'm using signal/slot to force the image refresh on the QML side, is there a nicer way to do this?
var oldSource = img.source;
img.source = "";
img.source = oldSource;
You can touch sourceSize property instead (it causes the image to be reloaded), but that is not in any way nicer than your solution.
deion last edited by
In one of my projects, SmartCam - http://sourceforge.net/projects/smartcam , I chose to use the approach of overriding the paint() method of QDeclarativeItem (Qt 4.x)
I always wondered why such a basic scenario (changing the provided image) was not supported in QImageProvider and one needed to use ugly hacks for this.
You can get the source code for SmartCam, the Qt/QML client is for BB10.
Perhaps Movie and AnimatedImage components are the answer, but I have never looked into those, so I can't say much about them.
seyed last edited by
@werispaul I know this is an very old post, but I submitting this reply post for anybody interested about it.
In my experience this scenario should be done using second option.
As you noticed, QImageProvider is not suitable for periodical update. Also notifying update from C++ to C++ through QML is a bad idea!
Last option has some performance impact since it is for older version of QtQuick and is not recommended any more (if possible) although it is more simple..
Therefore you should use second option :)