Solved Qt 6.2: QImageCapture is not ready - what is wrong?
-
Hi,
I have a code that captures images from camera and it works well with Qt 5 (PySide2). Now I port it to Qt 6.2 and faced some problems with image capture. Reducing it to minimal reproducible example I've found that my QImageCapture object never says it is ready for capture. Manual says that call ofcapture()
method should fail whenreadyForCapture()
is False but in reality it works and doesn't raise an error.
So either I do something wrong or there is a bug in Qt 6.2. You may find my code below. When I press the button I always have:PySide6.QtCore.QSize(1280, 720) Is capture ready: False
But if I call
capture()
after it - image is available (I haven't included it into example to reduce code size). The question is - are there any error in my code that keeps QImageCapture in "not ready" state?
My code is below:from PySide6.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QPushButton from PySide6.QtMultimedia import QCamera, QMediaCaptureSession, QImageCapture from PySide6.QtMultimediaWidgets import QVideoWidget class CameraWnd(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.layout = QVBoxLayout() self.viewfinder = QVideoWidget(self) self.layout.addWidget(self.viewfinder) self.viewfinder.setMinimumSize(720, 405) self.button = QPushButton(self) self.button.setText("Check state") self.layout.addWidget(self.button) self.wnd = QWidget(self) self.wnd.setLayout(self.layout) self.setCentralWidget(self.wnd) self.camera = QCamera() self.captureSession = QMediaCaptureSession() self.img_capture = QImageCapture(self.camera) self.captureSession.setCamera(self.camera) self.captureSession.setVideoOutput(self.viewfinder) self.captureSession.setImageCapture(self.img_capture) self.button.clicked.connect(self.on_button) self.img_capture.errorOccurred.connect(self.on_error) self.camera.errorOccurred.connect(self.on_cam_error) def on_button(self): print(self.viewfinder.videoSink().videoSize()) print(f"Is capture ready: {self.img_capture.isReadyForCapture()}") def on_error(self, _id, _error, error_str): print(f"Error: {error_str}") def on_cam_error(self, _error, error_str): print(f"Error: {error_str}")
-
@StarterKit Did you start the camera?
camera->start(); camera->searchAndLock();
-
@StarterKit Did you start the camera?
camera->start(); camera->searchAndLock();
-
@jsulm Bingo!
I occasionally removedself.camera.start()
from my code and haven't noticed it until your reply. Thanks a lot, that was the reason (Funny thing - everything worked and looked normally in this small example except object returned "not Ready" always)But the way, there are no
searchAndLock()
for QCamera in 6.2 anymore (that is one of my troubles and my old code was linked to it...)