<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Guys,<div class=""><br class=""></div><div class="">I wonder if anyone can point out a mistake here or if I have encountered a bug. If I try to use a VideOutput element in QML to display the live output from QCamera, via setViewfinder, I get a set fault. This works fine from C++, but I’m not sure if something is different in Python. Example follows (also attached):</div><div class=""><br class=""></div><div class=""><b class="">camerasource.py</b></div><div class=""><b class=""><br class=""></b></div><div class=""><div class=""><font face="Courier" class="">from PyQt5.QtCore import *</font></div><div class=""><font face="Courier" class="">from PyQt5.QtGui import *</font></div><div class=""><font face="Courier" class="">from PyQt5.QtWidgets import *</font></div><div class=""><font face="Courier" class="">from PyQt5.QtMultimedia import *</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">class CameraSource(QObject):</font></div><div class=""><font face="Courier" class=""> @pyqtProperty(QAbstractVideoSurface)</font></div><div class=""><font face="Courier" class=""> def videoSurface(self): return self._surface</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> @videoSurface.setter</font></div><div class=""><font face="Courier" class=""> def videoSurface(self, surface):</font></div><div class=""><font face="Courier" class=""> self._surface=surface</font></div><div class=""><font face="Courier" class=""> if self._surface:</font></div><div class=""><font face="Courier" class=""> self._surface.start(self._format)</font></div><div class=""><font face="Courier" class=""> self.camera.setViewfinder(self._surface)</font></div><div class=""><font face="Courier" class=""> self.camera.start()</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> def __init__(self, parent=None, **kwargs):</font></div><div class=""><font face="Courier" class=""> super().__init__(parent, **kwargs)</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> self.camera=QCamera(QCamera.FrontFace)</font></div><div class=""><font face="Courier" class=""> self.capture=QCameraImageCapture(self.camera, self)</font></div><div class=""><font face="Courier" class=""> self.recorder=QMediaRecorder(self.camera, self)</font></div><div class=""><font face="Courier" class=""> self._format=QVideoSurfaceFormat()</font></div><div class=""><font face="Courier" class=""> self._surface=None</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> @pyqtSlot(QVideoFrame)</font></div><div class=""><font face="Courier" class=""> def onNewVideoContentReceived(self, frame):</font></div><div class=""><font face="Courier" class=""> if self._surface: self._surface.present(frame) </font></div></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">main.qml</b></div><div class=""><b class=""><br class=""></b></div><div class=""><div class=""><font face="Courier" class="">import QtQuick 2.2</font></div><div class=""><font face="Courier" class="">import QtQuick.Controls 1.1</font></div><div class=""><font face="Courier" class="">import QtMultimedia 5.2</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">import CameraSource 1.0</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">ApplicationWindow {</font></div><div class=""><font face="Courier" class=""> visible: true</font></div><div class=""><font face="Courier" class=""> width: 1280</font></div><div class=""><font face="Courier" class=""> height: 720</font></div><div class=""><font face="Courier" class=""> color: "black"</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> VideoOutput {</font></div><div class=""><font face="Courier" class=""> id: video</font></div><div class=""><font face="Courier" class=""> source: camera</font></div><div class=""><font face="Courier" class=""> anchors.fill: parent</font></div><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> CameraSource {</font></div><div class=""><font face="Courier" class=""> id: camera</font></div><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class="">}</font></div></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">video_example.py</b></div><div class=""><b class=""><br class=""></b></div><div class=""><div class=""><font face="Courier" class="">from PyQt5.QtCore import *</font></div><div class=""><font face="Courier" class="">from PyQt5.QtGui import *</font></div><div class=""><font face="Courier" class="">from PyQt5.QtQuick import *</font></div><div class=""><font face="Courier" class="">from PyQt5.QtQml import *</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">from camerasource import *</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">if __name__=="__main__":</font></div><div class=""><font face="Courier" class=""> from sys import argv, exit</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> a=QApplication(argv)</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> qmlRegisterType(CameraSource, "CameraSource", 1, 0, "CameraSource")</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> engine=QQmlApplicationEngine()</font></div><div class=""><font face="Courier" class=""> engine.load(QUrl("./main.qml"))</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""> exit(a.exec_())</font></div></div><div class=""><b class=""><br class=""></b></div><div class="">Run ‘python video_example.py’ to test. If the ‘setViewfinder’ line in camerasource.py is commented out then the problem goes away, but obviously I don’t get any video displayed either. My setup is as follows:</div><div class=""><br class=""></div><div class="">OSX Yosemite</div><div class="">Python 3.4.3</div><div class="">Qt5.4</div><div class="">PyQt5.4.2</div><div class=""><br class=""></div><div class="">All help gratefully received,</div><div class=""><br class=""></div><div class="">Rob</div><div class=""><br class=""></div><div class=""></div></body></html>