Vinay
Vinay

Reputation: 81

How to open webcam and capture an image and save it on the system using Qt

I want to open the camera and have a button which I can push to capture an image. I have tried going through the documentation and also tried going through the example provided by Qt itself but I am not able to achieve this, please help me with this as I am new to Qt.

I refereed to the documentation provided by Qt and came up with this code:

camera = new QCamera;
viewfinder = new QCameraViewfinder;
camera->setViewfinder(viewfinder);
viewfinder->show();

camera->start();

When I run this code the light of the webcam is on but I am unable to see anything on the screen.

Upvotes: 2

Views: 807

Answers (1)

Zlatomir
Zlatomir

Reputation: 7034

Call camera->setViewFinder after viewfinder->show:

viewfinder->show();
camera->setViewfinder(viewfinder);
camera->start();

I don't know exactly why it does, the documentation doesn't explicitly say this (or at least i don't see it).

Upvotes: 3

Related Questions