3

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++?

4

1 に答える 1

4

私もこれに数回つまずきましたが、次のように解決しました:

QObject * obj = rootview->rootObject()->findChild<QObject *>("camera");
QVariant mediaObject = obj->property("mediaObject");
QCamera * camera = qvariant_cast<QCamera *>(mediaObject);

次に、 a を使用しQVideoRendererControlて のサブクラスを割り当て、QAbstractVideoSurfaceフレームを処理します。

于 2014-07-22T19:05:29.093 に答える