我想在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
怎么了?
这可能会解决它:
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();
}
}