- Qt 5.3
- Qt Multimedia
- QML Types
- Camera QML Type
- Qt 5.3.2 Reference Documentation

# Camera QML Type

Access viewfinder frames, and take photos and movies. More...

Import Statement: | `import QtMultimedia 5.0`

- List of all members, including inherited members

## Properties

- availability : enumeration
- cameraState : enumeration
- cameraStatus : enumeration
- captureMode : enumeration
- digitalZoom : real
- errorCode : enumeration
- errorString : string
- lockStatus : enumeration
- maximumDigitalZoom : real
- maximumOpticalZoom : real
- mediaObject : variant
- opticalZoom : real

## Signals

- cameraStateChanged(state)
- digitalZoomChanged(zoom)
- error(errorCode, errorString)
- lockStatusChanged()
- manualWhiteBalanceChanged(qreal)
- maximumDigitalZoomChanged(zoom)
- maximumOpticalZoomChanged(zoom)
- opticalZoomChanged(zoom)
- whiteBalanceModeChanged(Camera::WhiteBalanceMode)

## Methods

- searchAndLock()
- start()
- stop()
- unlock()

## Detailed Description

Camera is part of the QtMultimedia 5.0 module.

You can use `Camera` to capture images and movies from a camera, and manipulate the capture and processing settings that get applied to the images. To display the viewfinder you can use VideoOutput with the Camera set as the source.

    import QtQuick 2.0
    import QtMultimedia 5.0

    Item {
        width: 640
        height: 360

        Camera {
            id: camera

            imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash

            exposure {
                exposureCompensation: -1.0
                exposureMode: Camera.ExposurePortrait
            }

            flash.mode: Camera.FlashRedEyeReduction

            imageCapture {
                onImageCaptured: {
                    photoPreview.source = preview  // Show the preview in an Image
                }
            }
        }

        VideoOutput {
            source: camera
            anchors.fill: parent
            focus : visible // to receive focus and capture key events when visible
        }

        Image {
            id: photoPreview
        }
    }

The various settings and functionality of the Camera stack is spread across a few different child properties of Camera.

Property | Description
--- | ---
imageCapture | Methods and properties for capturing still images.
videoRecording | Methods and properties for capturing movies.
exposure | Methods and properties for adjusting exposure (aperture, shutter speed etc).
focus | Methods and properties for adjusting focus and providing feedback on autofocus progress.
flash | Methods and properties for controlling the camera flash.
imageProcessing | Methods and properties for adjusting camera image processing parameters.

Basic camera state management, error reporting, and simple zoom properties are available in the Camera itself. For integration with C++ code, the mediaObject property allows you to access the standard Qt Multimedia camera controls.

Many of the camera settings may take some time to apply, and might be limited to certain supported values depending on the hardware. Some camera settings may be set manually or automatically. These settings properties contain the current set value. For example, when autofocus is enabled the focus zones are exposed in the focus property.

## Property Documentation

availability : enumeration

This property holds the availability state of the camera.

The availability states can be one of the following:

Value | Description
--- | ---
Available | The camera is available to use
Busy | The camera is busy at the moment as it is being used by another process.
Unavailable | The camera is not available to use (there may be no camera hardware)
ResourceMissing | The camera cannot be used because of missing resources. It may be possible to try again at a later time.

cameraState : enumeration

This property holds the camera object's current state, which can be one of the following:

Value | Description
--- | ---
UnloadedState | The initial camera state, with the camera not loaded. The camera capabilities (with the exception of supported capture modes) are unknown. This state saves the most power, but takes the longest time to be ready for capture. While the supported settings are unknown in this state, you can still set the camera capture settings like codec, resolution, or frame rate.
LoadedState | The camera is loaded and ready to be configured. In the Idle state you can query camera capabilities, set capture resolution, codecs, and so on. The viewfinder is not active in the loaded state.
ActiveState | In the active state the viewfinder frames are available and the camera is ready for capture.

The default camera state is ActiveState.

cameraStatus : enumeration

This property holds the camera object's current status, which can be one of the following:

Value | Description
--- | ---
ActiveStatus | The camera has been started and can produce data, viewfinder displays video frames. Depending on backend, changing camera settings such as capture mode, codecs, or resolution in ActiveState may lead to changing the status to LoadedStatus and StartingStatus while the settings are applied, and back to ActiveStatus when the camera is ready.
StartingStatus | The camera is starting as a result of state transition to Camera.ActiveState. The camera service is not ready to capture yet.
StoppingStatus | The camera is stopping as a result of state transition from Camera.ActiveState to Camera.LoadedState or Camera.UnloadedState.
StandbyStatus | The camera is in the power saving standby mode. The camera may enter standby mode after some time of inactivity in the Camera.LoadedState state.
LoadedStatus | 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 such as resolution, frame rate, and codecs.
LoadingStatus | The camera device loading as a result of state transition from Camera.UnloadedState to Camera.LoadedState or Camera.ActiveState.
UnloadingStatus | The camera device is unloading as a result of state transition from Camera.LoadedState or Camera.ActiveState to Camera.UnloadedState.
UnloadedStatus | The initial camera status, with camera not loaded. The camera capabilities including supported capture settings may be unknown.
UnavailableStatus | The camera or camera backend is not available.

captureMode : enumeration

This property holds the camera capture mode, which can be one of the following:

Value | Description
--- | ---
CaptureViewfinder | Camera is only configured to display viewfinder.
CaptureStillImage | Prepares the Camera for capturing still images.
CaptureVideo | Prepares the Camera for capturing video.

digitalZoom : real

This property holds the current digital zoom factor.

errorCode : enumeration

This property holds the last error code.

See also error and errorString.

errorString : string

This property holds the last error string, if any.

See also error and errorCode.

lockStatus : enumeration

This property holds the status of all the requested camera locks.

The status can be one of the following values:

Value | Description
--- | ---
Unlocked | The application is not interested in camera settings value. The camera may keep this parameter without changes, which is common with camera focus, or adjust exposure and white balance constantly to keep the viewfinder image nice.
Searching | The application has requested the camera focus, exposure, or white balance lock with searchAndLock(). This state indicates the camera is focusing or calculating exposure and white balance.

Locked

The camera focus, exposure, or white balance is locked. The camera is ready to capture, and the application may check the exposure parameters.

The locked state usually means the requested parameter stays the same, except in cases where the parameter is requested to be updated constantly. 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.

maximumDigitalZoom : real

This property holds the maximum digital zoom factor supported, or 1.0 if digital zoom is not supported.

maximumOpticalZoom : real

This property holds the maximum optical zoom factor supported, or 1.0 if optical zoom is not supported.

mediaObject : variant

This property holds the media object for the camera.

opticalZoom : real

This property holds the current optical zoom factor.

## Signal Documentation

cameraStateChanged(state)

This signal is emitted when the camera state has changed to state. Since the state changes may take some time to occur this signal may arrive sometime after the state change has been requested.

The corresponding handler is `onCameraStateChanged`.

digitalZoomChanged(zoom)

This signal is emitted when the digital zoom setting has changed to zoom.

The corresponding handler is `onDigitalZoomChanged`.

error(errorCode, errorString)

This signal is emitted when an error occurs. The enumeration value errorCode is one of the values defined below, and a descriptive string value is available in errorString.

Value | Description
--- | ---
NoError | No errors have occurred.
CameraError | An error has occurred.
InvalidRequestError | System resource doesn't support requested functionality.
ServiceMissingError | No camera service available.
NotSupportedFeatureError | The feature is not supported.

The corresponding handler is `onError`.

See also errorCode and errorString.

lockStatusChanged()

This signal is emitted when the lock status (focus, exposure etc) changes. This can happen when locking (e.g. autofocusing) is complete or has failed.

The corresponding handler is `onLockStatusChanged`.

manualWhiteBalanceChanged(qreal)

This signal is emitted when the `manualWhiteBalance` property is changed.

The corresponding handler is `onManualWhiteBalanceChanged`.

maximumDigitalZoomChanged(zoom)

This signal is emitted when the maximum digital zoom setting has changed to zoom. This can occur when you change between video and still image capture modes, or the capture settings are changed.

The corresponding handler is `onMaximumDigitalZoomChanged`.

maximumOpticalZoomChanged(zoom)

This signal is emitted when the maximum optical zoom setting has changed to zoom. This can occur when you change between video and still image capture modes, or the capture settings are changed.

The corresponding handler is `onMaximumOpticalZoomChanged`.

opticalZoomChanged(zoom)

This signal is emitted when the optical zoom setting has changed to zoom.

The corresponding handler is `onOpticalZoomChanged`.

whiteBalanceModeChanged(Camera::WhiteBalanceMode)

This signal is emitted when the `whiteBalanceMode` property is changed.

The corresponding handler is `onWhiteBalanceModeChanged`.

## Method Documentation

searchAndLock()

Start focusing, exposure and white balance calculation.

This is appropriate to call when the camera focus button is pressed (or on a camera capture button half-press). If the camera supports autofocusing, information on the focus zones is available through the focus property.

start()

Starts the camera. Viewfinder frames will be available and image or movie capture will be possible.

stop()

Stops the camera, but leaves the camera stack loaded.

unlock()

Unlock focus, exposure and white balance locks.