First, we should establish whether the device has any cameras. This helps us determine specifics about the use of the camera and other camera specifications, such as the orientation or position on the device.
For this, we will use QCameraInfo
.
We can get a list of cameras using the QCameraInfo::availableCameras()
function:
Note
The source code can be found in this book's Git repository under the Chapter09-4
directory, in the cp9
branch.
QList<QCameraInfo>cameras=QCameraInfo::availableCameras(); foreach(constQCameraInfo&cameraInfo,cameras) ui->textEdit->insertPlainText(cameraInfo.deviceName()+"\n");
On my Android device, I see two cameras, named back
and front
. You can also check for front
and back
cameras using QCameraInfo::position()
, which will return one of the following:
QCamera::UnspecifiedPosition
QCamera::BackFace
QCamera::FrontFace
FrontFace
means that the camera lens is on the same side as the screen. You can then use QCameraInfo
to construct...