2013-09-05 44 views
0

我想在qt快速应用程序的背景下从网络摄像头呈现视频。 我用这个代码5.1.1的文件来渲染测试视频:使用QtQuick进行视频播放

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 

什么是错的?

+1

它的错误与文档,正确的语法都没有 “锚:parent.fill”,而是 “anchors.fill:父”(如在鼠标区域)。哪一页文件?为了修复它 – gbdivers

+0

@Guillaume Belz here http://qt-project.org/doc/qt-5.0/qtmultimedia/qml-qtmultimedia5-mediaplayer.html – iMath

回答

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(); 
    } 
}