我想在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
有什么问题?
答案 0 :(得分: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();
}
}