Dealing with the disappearance of QVideoProbe and QCameraViewfinder in Qt 6.x
Solved
General and Desktop
-
Hello,
Under Qt 5.x, I was using QVideoProbe to get images from a camera. Unfortunately, this function has disappeared in version 6.xconst QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); if (!cameras.empty()) { camera_sensor = new QCamera(QCamera::BackFace); if (camera_sensor) { viewfinder = new QCameraViewfinder(); if (viewfinder) { camera_sensor->setViewfinder(viewfinder); camera_sensor->setCaptureMode(QCamera::CaptureStillImage); videoProbe = new QVideoProbe(this); if (videoProbe->setSource(camera_sensor)) { // Probing succeeded, videoProbe->isValid() should be true. connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(recupererImagesCamera(QVideoFrame))); } camera_sensor->start(); // Viewfinder frames should now also be emitted by // the video probe, even in still image capture mode. // Another alternative is to install the probe on a // QMediaRecorder connected to the camera to get the // recorded frames, if they are different from the // viewfinder frames. } }
I try painfully to go through the QVideoSink class but without success.
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs(); if (!cameras.empty()) { camera_sensor = new QCamera(QCameraDevice::BackFace); if (camera_sensor) { viewfinder = new QVideoSink(this); if (viewfinder) { videoFrame = new QMediaCaptureSession(); videoFrame->setCamera(camera_sensor); videoFrame->setVideoSink(viewfinder); connect(viewfinder, &QVideoSink::videoFrameChanged, this, &QWinStars3View::recupererImagesCamera2); } } }
I try painfully to go through the QVideoSink class but without success.
Thanx !
-
Hello, have you checked the Camera Example came with Qt installation?
From my understanding, we use a QVideoWidget as the viewfinder (preview widget), and you don't need to create a QVideoSink because QVideoWidget already have one.
So should be something likeviewfinder = new QVideoWidget(this); videoFrame = new QMediaCaptureSession(); videoFrame->setCamera(camera_sensor); videoFrame->setVideoOutput(viewfinder); connect(viewfinder->videoSink(), &QVideoSink::videoFrameChanged, this, &QWinStars3View::recupererImagesCamera2); camera_sensor->start();
If you don't need a preview widget, then use QVideoSink only as in your code. Seems that should work after you start the camera.
-
Thanks Bonnie!
It works perfectly (I will use QVideoSink )!
Have a great day!