According to the docs “If source is zero, this probe will be deactivated”
But calling setSource(0) gives the following exception:
Exception has occurred: TypeError 'PySide2.QtMultimedia.QVideoProbe.setSource' called with wrong argument types: PySide2.QtMultimedia.QVideoProbe.setSource(int) Supported signatures: PySide2.QtMultimedia.QVideoProbe.setSource(PySide2.QtMultimedia.QMediaObject) PySide2.QtMultimedia.QVideoProbe.setSource(PySide2.QtMultimedia.QMediaRecorder)
Im running my code on raspberry pi 4 with Rpi Os Bullseye 64bit and PySide2 version 5.15.2.
Example code:
import sys from PySide2 import QtCore, QtMultimedia from PySide2.QtMultimedia import * from PySide2.QtMultimediaWidgets import * from PySide2.QtWidgets import * class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__(parent) self.available_cameras = QCameraInfo.availableCameras() self.camera = QCamera(self.available_cameras[0]) self.probe = QtMultimedia.QVideoProbe(self) self.probe.videoFrameProbed.connect(self.processFrame) self.probe.setSource(self.camera) self.probe.setSource(0) def processFrame(self, frame): pass if __name__ == "__main__": app = QApplication(sys.argv) mainWindow = MainWindow() mainWindow.show() sys.exit(app.exec_())
Advertisement
Answer
The source object can be cleared like this:
self.probe.setSource(None)
In C++, passing zero to a pointer argument means the function will recieve a null pointer. Since this can’t be done explicitly in Python, PySide/PyQt allow None
to be passed instead.
Generally speaking, it’s always advisable to consult the Qt Docs in cases like this. The PySide/PyQt docs are a work in progress and are mostly auto-generated from the Qt Docs. This can often result in somewhat garbled or misleading descriptions that don’t accurately reflect how the given API works in practice.