QCameraDevice Class

The QCameraDevice class provides general information about camera devices. More...

Header: #include <QCameraDevice>
CMake: find_package(Qt6 COMPONENTS Multimedia REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
Since: Qt 5.3

Public Types

enum Position { UnspecifiedPosition, BackFace, FrontFace }

Public Functions

QCameraDevice(const QCameraDevice &other)
QCameraDevice()
QCameraDevice &operator=(const QCameraDevice &other)
~QCameraDevice()
QString description() const
QByteArray id() const
bool isDefault() const
bool isNull() const
QCameraDevice::Position position() const
QList<QCameraFormat> videoFormats() const
bool operator!=(const QCameraDevice &other) const
bool operator==(const QCameraDevice &other) const

Detailed Description

QCameraDevice lets you query for camera devices that are currently available on the system.

The static functions defaultCamera() and availableCameras() provide you a list of all available cameras.

This example prints the name of all available cameras:

 const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
 for (const QCameraDevice &cameraDevice : cameras)
     qDebug() << cameraDevice.description();

A QCameraDevice can be used to construct a QCamera. The following example instantiates a QCamera whose camera device is named 'mycamera':

 const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
 for (const QCameraDevice &cameraDevice : cameras) {
     if (cameraDevice.description() == "mycamera")
         camera = new QCamera(cameraDevice);
 }

You can also use QCameraDevice to get general information about a camera device such as description, physical position on the system, or camera sensor orientation.

 QCamera myCamera;
 QCameraDevice cameraDevice = camera->cameraDevice();

 if (cameraDevice.position() == QCameraDevice::FrontFace)
     qDebug() << "The camera is on the front face of the hardware system.";
 else if (cameraDevice.position() == QCameraDevice::BackFace)
     qDebug() << "The camera is on the back face of the hardware system.";

 qDebug() << "The camera sensor orientation is " << cameraDevice.orientation() << " degrees.";

See also QCamera.

Member Type Documentation

[since 5.3] enum QCameraDevice::Position

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

ConstantValueDescription
QCameraDevice::UnspecifiedPosition0The camera position is unspecified or unknown.
QCameraDevice::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.
QCameraDevice::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 QCameraDevice::position().

Member Function Documentation

QCameraDevice::QCameraDevice(const QCameraDevice &other)

Constructs a copy of other.

QCameraDevice::QCameraDevice()

Constructs a null camera device

QCameraDevice &QCameraDevice::operator=(const QCameraDevice &other)

Sets the QCameraDevice object to be equal to other.

QCameraDevice::~QCameraDevice()

Destroys the QCameraDevice.

QString QCameraDevice::description() const

Returns the human-readable description of the camera.

Note: Getter function for property description.

QByteArray QCameraDevice::id() const

Returns the device id of the camera

This is a unique ID to identify the camera and may not be human-readable.

Note: Getter function for property id.

bool QCameraDevice::isNull() const

Returns true if this QCameraDevice is null or invalid.

QCameraDevice::Position QCameraDevice::position() const

Returns the physical position of the camera on the hardware system.

Note: Getter function for property position.

QList<QCameraFormat> QCameraDevice::videoFormats() const

Returns the video formats supported by the camera.

bool QCameraDevice::operator!=(const QCameraDevice &other) const

Returns true if this QCameraDevice is different from other.

bool QCameraDevice::operator==(const QCameraDevice &other) const

Returns true if this QCameraDevice is equal to other.