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
- captureMode : QCamera::CaptureModes
- lockStatus : const QCamera::LockStatus
- state : const QCamera::State
- status : const QCamera::Status
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.
| Constant | Value | Description |
|---|---|---|
QCamera::CaptureViewfinder | 0 | Camera is only configured to display viewfinder. |
QCamera::CaptureStillImage | 0x01 | Camera is configured for still frames capture. |
QCamera::CaptureVideo | 0x02 | Camera is configured for video capture. |
enum QCamera::Error
This enum holds the last error code.
| Constant | Value | Description |
|---|---|---|
QCamera::NoError | 0 | No errors have occurred. |
QCamera::CameraError | 1 | An error has occurred. |
QCamera::InvalidRequestError | 2 | System resource doesn't support requested functionality. |
QCamera::ServiceMissingError | 3 | No camera service available. |
QCamera::NotSupportedFeatureError | 4 | The feature is not supported. |
enum QCamera::LockChangeReason
This enum holds the reason why the camera lock status changed.
| Constant | Value | Description |
|---|---|---|
QCamera::UserRequest | 0 | The lock status changed in result of user request, usually to unlock camera settings. |
QCamera::LockAcquired | 1 | The lock status successfuly changed to QCamera::Locked. |
QCamera::LockFailed | 2 | The camera failed to acquire the requested lock in result of autofocus failure, exposure out of supported range, etc. |
QCamera::LockLost | 3 | The camera is not able to maintain the requested lock any more. Lock status is changed to QCamera::Unlocked. |
QCamera::LockTemporaryLost | 4 | The 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.
| Constant | Value | Description |
|---|---|---|
QCamera::Unlocked | 0 | The 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::Searching | 1 | The 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::Locked | 2 | The 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.
| Constant | Value | Description |
|---|---|---|
QCamera::NoLock | 0 | |
QCamera::LockExposure | 0x01 | Lock camera exposure. |
QCamera::LockWhiteBalance | 0x02 | Lock the white balance. |
QCamera::LockFocus | 0x04 | Lock camera focus. |
enum QCamera::Position
This enum specifies the physical position of the camera on the system hardware.
| Constant | Value | Description |
|---|---|---|
QCamera::UnspecifiedPosition | 0 | The camera position is unspecified or unknown. |
QCamera::BackFace | 1 | The 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::FrontFace | 2 | The 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.
| Constant | Value | Description |
|---|---|---|
QCamera::UnloadedState | 0 | The 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::LoadedState | 1 | The 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::ActiveState | 2 | In 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.
| Constant | Value | Description |
|---|---|---|
QCamera::ActiveStatus | 8 | The 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::StartingStatus | 6 | The camera is starting in result of state transition to QCamera::ActiveState. The camera service is not ready to capture yet. |
QCamera::StoppingStatus | 7 | The camera is stopping in result of state transition from QCamera::ActiveState to QCamera::LoadedState or QCamera::UnloadedState. |
QCamera::StandbyStatus | 5 | The 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::LoadedStatus | 4 | The 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::LoadingStatus | 2 | The camera device loading in result of state transition from QCamera::UnloadedState to QCamera::LoadedState or QCamera::ActiveState. |
QCamera::UnloadingStatus | 3 | The camera device is unloading in result of state transition from QCamera::LoadedState or QCamera::ActiveState to QCamera::UnloadedState. |
QCamera::UnloadedStatus | 1 | The initial camera status, with camera not loaded. The camera capabilities including supported capture settings may be unknown. |
QCamera::UnavailableStatus | 0 | The 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) |