(Difference between revisions)

Secondary camera in QML

From Nokia Developer Wiki
Jump to: navigation, search
xmlich02 (Talk | contribs)
(Xmlich02 -)
chintandave_er (Talk | contribs)
(Chintandave er - updated article metadata)
Line 21: Line 21:
|update-by= <!-- After significant update: [[User:username]]-->
|update-by= <!-- After significant update: [[User:username]]-->
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|creationdate= <!-- Format YYYYMMDD -->
|creationdate= 20120607
|author= <!-- Display as link [[User:username]] -->
|author= [[User:xmlich02]]  

Revision as of 11:41, 9 June 2012

This article explains how to use the secondary camera in QML

Note.pngNote: This is an entry in the PureView Imaging Competition 2012Q2

Article Metadata
Code ExampleTested with
Devices(s): N9
Platform(s): Qt 4.6 and later
Device(s): must have secondary camera
Dependencies: qt mobility
Keywords: Camera, QML
Created: xmlich02 (07 Jun 2012)
Last edited: chintandave_er (09 Jun 2012)



This article describes how to use the secondary camera in QML. The article [1] describes how to use the primary camera in various ways. However, access to the secondary camera is not available in QML.

Current solution

The secondary camera (i.e. frontal camera) is available though the C++ API. The registration of the component in QML is possible. However, this component does not provide the methods which are in the QML Camera component [2].

#include <QGraphicsVideoItem>
FrontCameraApp::FrontCameraApp(QDeclarativeItem *parent) : QDeclarativeItem(parent)
myViewfinder = new QGraphicsVideoItem(this);
QByteArray frontCamera = QCamera::availableDevices()[1];
myCamera = new QCamera(frontCamera);

The multimedia part from qt mobility has to be included in project.

CONFIG += mobility
MOBILITY += multimedia

Also, the FrontCameraApp object has to be registered for QML.

    qmlRegisterType<FrontCameraApp>("cz.vutbr.fit.pcmlich", 1, 0, "CameraFront");

The use in QML is as follows:

import com.nokia.meego 1.0
import cz.vutbr.fit.pcmlich 1.0
// import QtMultimediaKit 1.1
Page {
CameraFront {
anchors.fill: parent;
// or primary camera
Camera {
anchors.fill: parent;


Additional features

Since Qt mobility is open source, you can download the source codes from [3]. The implementation of the Camera element is in /plugins/declarative/multimedia/qdeclarativecamera.cpp. In order to use of this class in your own project it is necessary to modify its code to work with secondary camera as follows:

QDeclarativeCamera::QDeclarativeCamera(QDeclarativeItem *parent) :
// m_camera = new QCamera(this); // remove this line
QByteArray frontCamera = QCamera::availableDevices()[1]; // add this line
m_Camera = new QCamera(frontCamera); // add this line

Next, it is necessary to add included private header files to your project.

#include "qdeclarativecamera_p.h"
#include "qdeclarativecamerapreviewprovider_p.h"

There could be a conflict in the class names QDeclarativeCamera and other problems, so it is recommended to perform refactoring of QDeclarativeCamera class. Finally, the modified class is registered into QML, as is described in the previous section.


The image from the secondary camera could be confusing to the user. Therefore it is appropriate to flip it.

        transform: Rotation { origin.x: frontcam.width/2; origin.y: frontcam.height/2; axis { x: 0; y: 1; z: 0 } angle: 180  }

The primary and secondary cameras cannot be opened at same time.


After these modifications, we have a QML component for the secondary camera which allows us modify white balance mode, exposure compensation, and other configuration of the secondary camera. It is also possible to capture images and monitor camera states. This solution is only a workaround, since the Qt Mobility is not providing a suitable interface for the secondary camera. All mentioned components are available in the attached file Media:SecondaryCameraInQml.tar.gz

92 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.