I create an app with the cross-platform Qt
and on this app, I need to display the result of one QCamera
on two different screens. This involve to link two QCameraViewFinder
on the same QCamera
.
My code is :
QCameraViewFinder* viewfinder = new QCameraViewFinder();
QCamera* camera = new QCamera();
viewfinder->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
camera->setViewfinder(ui->viewfinder);
QCamera::CaptureModes captureMode = QCamera::CaptureStillImage ;
camera->setCaptureMode(captureMode);
The problem here is that I can't use another QCameraViewFinder to track my QCamera. And I need to do that because I would like to display two QCameraViewFinder on two different screens.
I'm really stuck on this topic so if some people have a solution, that would be great!
You can actually create two distinct instances of QCamera, and set two distinct viewfinders to them, but you'll not be able to start the camera twice (i.e. you will end up with some kind of busy device error).
If all you need is a simple viewfinder implementation, you can subclass
QAbstractVideoSurface
and forward video frames through signals, this way:sharedviewfinder.h
sharedviewfinder.cpp
To show the forwarded frames, in a widget of your choice, have a
QLabel
and a slot like this:You can now set the shared viewfinder to a camera object, and connect it with more than one view:
I hope this works out of the box, anyway you may want to change the color format I set to RGB32. Also, notice I move the views to show them on both the screens I have. The example code I'm providing has been successfully tested (but in a very shallow way) on a Ubuntu 16.10 Asus laptop.