QCamera Class

The QCamera class provides interface for system camera devices. More...

Header: #include <QCamera>
qmake: QT += multimedia
Inherits: QMediaObject

Public Types

struct FrameRateRange
enum CaptureMode { CaptureViewfinder, CaptureStillImage, CaptureVideo }
enum Error { NoError, CameraError, InvalidRequestError, ServiceMissingError, NotSupportedFeatureError }
enum LockChangeReason { UserRequest, LockAcquired, LockFailed, LockLost, LockTemporaryLost }
enum LockStatus { Unlocked, Searching, Locked }
enum LockType { NoLock, LockExposure, LockWhiteBalance, LockFocus }
enum Position { UnspecifiedPosition, BackFace, FrontFace }
enum State { UnloadedState, LoadedState, ActiveState }
enum Status { ActiveStatus, StartingStatus, StoppingStatus, StandbyStatus, LoadedStatus, …, UnavailableStatus }

Properties

Public Functions

QCamera::CaptureModes captureMode() const
QCamera::LockStatus lockStatus() const
QCamera::LockStatus lockStatus(QCamera::LockType lock) const
QCamera::State state() const
QCamera::Status status() const

Public Slots

void setCaptureMode(QCamera::CaptureModes mode)

Signals

void captureModeChanged(QCamera::CaptureModes)
void lockStatusChanged(QCamera::LockType lock, QCamera::LockStatus status, QCamera::LockChangeReason reason)
void lockStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason)
void stateChanged(QCamera::State state)
void statusChanged(QCamera::Status status)

Detailed Description

QCamera can be used with QCameraViewfinder for viewfinder display, QMediaRecorder for video recording and QCameraImageCapture for image taking.

You can use QCameraInfo to list available cameras and choose which one to use.

 const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
 for (const QCameraInfo &cameraInfo : cameras) {
     if (cameraInfo.deviceName() == "mycamera")
         camera = new QCamera(cameraInfo);
 }

See the camera overview for more information.

Member Type Documentation

enum QCamera::CaptureMode

This enum holds the capture mode of the camera.

ConstantValueDescription
QCamera::CaptureViewfinder0Camera is only configured to display viewfinder.
QCamera::CaptureStillImage0x01Camera is configured for still frames capture.
QCamera::CaptureVideo0x02Camera is configured for video capture.

enum QCamera::Error

This enum holds the last error code.

ConstantValueDescription
QCamera::NoError0No errors have occurred.
QCamera::CameraError1An error has occurred.
QCamera::InvalidRequestError2System resource doesn't support requested functionality.
QCamera::ServiceMissingError3No camera service available.
QCamera::NotSupportedFeatureError4The feature is not supported.

enum QCamera::LockChangeReason

This enum holds the reason why the camera lock status changed.

ConstantValueDescription
QCamera::UserRequest0The lock status changed in result of user request, usually to unlock camera settings.
QCamera::LockAcquired1The lock status successfuly changed to QCamera::Locked.
QCamera::LockFailed2The camera failed to acquire the requested lock in result of autofocus failure, exposure out of supported range, etc.
QCamera::LockLost3The camera is not able to maintain the requested lock any more. Lock status is changed to QCamera::Unlocked.
QCamera::LockTemporaryLost4The lock is lost, but the camera is working hard to reacquire it. This value may be used in continuous focusing mode, when the camera loses the focus, the focus lock state is changed to Qcamera::Searching with LockTemporaryLost reason.

enum QCamera::LockStatus

This enum holds the overall status for all the requested camera locks.

ConstantValueDescription
QCamera::Unlocked0The application is not interested in camera settings value. The camera may keep this parameter without changes, this is common with camera focus, or adjust exposure and white balance constantly to keep the viewfinder image nice.
QCamera::Searching1The application has requested the camera focus, exposure or white balance lock with QCamera::searchAndLock(). This state indicates the camera is focusing or calculating exposure and white balance.
QCamera::Locked2The camera focus, exposure or white balance is locked. The camera is ready to capture, application may check the exposure stays the same, parameters. The Locked status usually means the requested parameter except in the cases when the parameter is requested to be constantly updated. For example, in continuous focusing mode, the focus is considered locked as long as the object is in focus, even while the actual focusing distance may be constantly changing.

enum QCamera::LockType

This enum holds the camera lock type.

ConstantValueDescription
QCamera::NoLock0 
QCamera::LockExposure0x01Lock camera exposure.
QCamera::LockWhiteBalance0x02Lock the white balance.
QCamera::LockFocus0x04Lock camera focus.

enum QCamera::Position

This enum specifies the physical position of the camera on the system hardware.

ConstantValueDescription
QCamera::UnspecifiedPosition0The camera position is unspecified or unknown.
QCamera::BackFace1The camera is on the back face of the system hardware. For example on a mobile device, it means it is on the opposite side to that of the screen.
QCamera::FrontFace2The camera is on the front face of the system hardware. For example on a mobile device, it means it is on the same side as that of the screen. Viewfinder frames of front-facing cameras are mirrored horizontally, so the users can see themselves as looking into a mirror. Captured images or videos are not mirrored.

This enum was introduced or modified in Qt 5.3.

See also QCameraInfo::position().

enum QCamera::State

This enum holds the current state of the camera.

ConstantValueDescription
QCamera::UnloadedState0The initial camera state, with camera not loaded. The camera capabilities, except supported capture modes, are unknown. While the supported settings are unknown in this state, it's allowed to set the camera capture settings like codec, resolution, or frame rate.
QCamera::LoadedState1The camera is loaded and ready to be configured. In this state it's allowed to query camera capabilities, set capture resolution, codecs, etc. The viewfinder is not active in the loaded state. The camera consumes power in the loaded state.
QCamera::ActiveState2In the active state as soon as camera is started the viewfinder displays video frames and the camera is ready for capture.

enum QCamera::Status

This enum holds the current status of the camera.

ConstantValueDescription
QCamera::ActiveStatus8The camera has been started and can produce data. The viewfinder displays video frames in active state. Depending on backend, changing some camera settings like capture mode, codecs or resolution in ActiveState may lead to changing the camera status to LoadedStatus and StartingStatus while the settings are applied and back to ActiveStatus when the camera is ready.
QCamera::StartingStatus6The camera is starting in result of state transition to QCamera::ActiveState. The camera service is not ready to capture yet.
QCamera::StoppingStatus7The camera is stopping in result of state transition from QCamera::ActiveState to QCamera::LoadedState or QCamera::UnloadedState.
QCamera::StandbyStatus5The camera is in the power saving standby mode. The camera may come to the standby mode after some time of inactivity in the QCamera::LoadedState state.
QCamera::LoadedStatus4The camera is loaded and ready to be configured. This status indicates the camera device is opened and it's possible to query for supported image and video capture settings, like resolution, framerate and codecs.
QCamera::LoadingStatus2The camera device loading in result of state transition from QCamera::UnloadedState to QCamera::LoadedState or QCamera::ActiveState.
QCamera::UnloadingStatus3The camera device is unloading in result of state transition from QCamera::LoadedState or QCamera::ActiveState to QCamera::UnloadedState.
QCamera::UnloadedStatus1The initial camera status, with camera not loaded. The camera capabilities including supported capture settings may be unknown.
QCamera::UnavailableStatus0The camera or camera backend is not available.

Property Documentation

captureMode : QCamera::CaptureModes

The type of media (video or still images), the camera is configured to capture.

It's allowed to change capture mode in any camera state, but if the camera is currently active, chaging capture mode is likely to lead to camera status chaged to QCamera::LoadedStatus, QCamera::LoadingStatus, and when the camera is ready to QCamera::ActiveStatus.

Access functions:

QCamera::CaptureModes captureMode() const
void setCaptureMode(QCamera::CaptureModes mode)

Notifier signal:

void captureModeChanged(QCamera::CaptureModes)

lockStatus : const QCamera::LockStatus

This property holds the overall status for all the requested camera locks.

Access functions:

QCamera::LockStatus lockStatus() const
QCamera::LockStatus lockStatus(QCamera::LockType lock) const

Notifier signal:

void lockStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason)
void lockStatusChanged(QCamera::LockType lock, QCamera::LockStatus status, QCamera::LockChangeReason reason)

state : const QCamera::State

This property holds the current state of the camera object.

Access functions:

QCamera::State state() const

Notifier signal:

void stateChanged(QCamera::State state)

status : const QCamera::Status

This property holds the current status of the camera object.

Access functions:

QCamera::Status status() const

Notifier signal:

void statusChanged(QCamera::Status status)