Issue with QCamera in PyQt6

Phil Thompson phil at riverbankcomputing.com
Tue Nov 9 14:28:01 GMT 2021


On 08/11/2021 08:14, RedHuli wrote:
> Hello,
> 
> I was wondering if someone could help me with my issue. I want to 
> update my
> code from PyQt5 to PyQt6. I need to use QCamera, but every time I do I 
> get
> the following error:
> 
> zsh: segmentation fault
> /Library/Frameworks/Python.framework/Versions/3.9/bin/python3
> test_camera.py
> 
> 
> No matter what I do, I still get an error. I've played around with
> QMediaPlayer and QVideoWidget. I am not sure which new classes to use 
> in
> PyQt6 to get the camera to play. Below is the minimum code (I believe)
> should get the camera working:
> 
> 
> # Import necessary modules
> import sys
> from PyQt6.QtWidgets import QApplication
> from PyQt6.QtMultimedia import (QCamera, QMediaCaptureSession, 
> QMediaDevices
> )
> from PyQt6.QtMultimediaWidgets import QVideoWidget
> 
> app = QApplication(sys.argv)
> 
> video_widget = QVideoWidget()
> video_widget.resize(640, 480)
> video_widget.show()
> 
> camera = QCamera(QMediaDevices.defaultVideoInput())
> camera.start()
> 
> mediaCaptureSession = QMediaCaptureSession()
> mediaCaptureSession.setCamera(camera)
> mediaCaptureSession.setVideoOutput(video_widget)
> 
> sys.exit(app.exec())
> 
> 
> Thanks for your help!
> 
> 
> Joshua Willman

It worked fine for me on macOS.

Phil


More information about the PyQt mailing list