0

我想在 qt 快速应用程序的背景中渲染来自网络摄像头的视频。我使用 5.1.1 文档中的这段代码来渲染测试视频:

    import QtQuick 2.0
    import QtMultimedia 5.0

    Item {
        MediaPlayer {
            id: mediaplayer
            source: "groovy_video.mp4"
        }

        VideoOutput {
            anchors: parent.fill
            source: mediaplayer
        }

        MouseArea {
            id: playArea
            anchors.fill: parent
            onPressed: mediaplayer.play();
        }
    }

我没有 QtQuick 经验,即使示例(未修改)也无法正常工作,这会令人沮丧:

Invalid property assignment: "anchors" is a read-only property 
anchors: parent.fill

怎么了?

4

1 回答 1

0

这可能会解决它:

import QtQuick 2.0
import QtMultimedia 5.0

Item {
    height: video.implicitHeight // or video.height
    width: video.implicitWidth // or video.width
    MediaPlayer {
        id: mediaplayer
        source: "groovy_video.mp4"
    }

    VideoOutput {
        id: video
        source: mediaplayer
    }

    MouseArea {
        id: playArea
        anchors.fill: parent
        onPressed: mediaplayer.play();
    }
}
于 2013-09-05T21:04:56.053 回答