I'm trying to create a QML item, defined in C++, that would intercept frames from a QML Camera
before they are displayed by a VideoOutput
. Something like:
Window {
Camera {
id: camera
}
MyFrameinterceptor {
id: myprocessing
source: camera.mediaObject
}
VideoOutput {
id: feedback
source: myprocessing
}
}
According to this comment, the mediaObject property of a Camera
item can be used to access the C++ part of the Camera
.
However, when I try to access the mediaObject from QML, e.g. with
Text {
text: qsTr(camera.mediaObject.objectName)
}
I get a TypeError: Cannot read property 'objectName' of undefined
When I try to use the camera.mediaObject property from C++, I get similar messages letting me think that mediaObject is undefined, uninitialized or not existing.
I'm new to Qt, so I may miss something really stupid, like starting the camera or what not... But I have the same problem with a MediaPlayer
item
How can I access the mediaObject of a QML Camera from C++?
I tripped into this a couple of times as well, I resolved it like so:
QObject * obj = rootview->rootObject()->findChild<QObject *>("camera");
QVariant mediaObject = obj->property("mediaObject");
QCamera * camera = qvariant_cast<QCamera *>(mediaObject);
I then use a QVideoRendererControl
to assign a subclass of QAbstractVideoSurface
to process frames.