×
Namespaces

Variants
Actions
Revision as of 17:51, 8 April 2010 by olympio (Talk | contribs)

Display camera preview using Qt Mobility

From Nokia Developer Wiki
Jump to: navigation, search
ID Creation date 28th Mar 2010
Platform S60 5th Edition Tested on devices Nokia N97 Mini
Category Qt for Symbian Subcategory Qt Mobility API


Keywords (APIs, classes, methods, functions): QCamera, QVideoWidget

Tip.pngTip: Read this article before moving forward: Setting up environment for Qt Mobility API

Contents

Overview

Display Camera Preview on Widget using Qt Mobility APIs

Keywords

Project configuration file (.Pro file)

  • Add the Qt Mobility project configuration option in the .Pro file as shown below
CONFIG += mobility
MOBILITY += multimedia

Header File

#include <qcamera.h>
#include <qvideowidget.h>
class CameraApp : publoc QWidget
{
Q_OBJECT
public:
CameraApp(QWidget* parent = 0);
~CameraApp();
public slots:
void error(QCamera::Error);
private:
void InitCamera();
 
private:
QStackedWidget* m_stackedWidget;
QCamera* m_camera;
QVideoWidget* m_videoWidget;
};

Source File

CameraApp::CameraApp(QWidget *parent) :
QWidget(parent), m_camera(0)
{
QGridLayout* layout = new QGridLayout;
layout->setSpacing(0);
layout->setMargin(0);
 
m_videoWidget = new QVideoWidget();
 
QPalette black(Qt::black);
m_stackedWidget = new QStackedWidget();
m_stackedWidget->setPalette(black);
 
m_stackedWidget->addWidget(m_videoWidget);
 
m_stackedWidget->setCurrentIndex(0);
layout->addWidget(m_stackedWidget);
 
setLayout(layout);
 
InitCamera();
}
void CameraApp::initCamera() {
QByteArray cameraDevice = QCamera::availableDevices()[0];
m_camera = new QCamera(cameraDevice);
 
connect(m_camera, SIGNAL(error(QCamera::Error)), this, SLOT(error(QCamera::Error)));
 
m_camera->setFocusMode(QCamera::AutoFocus);
 
m_videoWidget->setMediaObject(m_camera);
m_videoWidget->setAspectRatioMode(QVideoWidget::KeepAspectRatio);
 
if (m_camera->state() == QCamera::ActiveState) {
m_camera->stop();
}
m_camera->start();
}
void CameraApp::error(QCamera::Error e) {
switch (e) {
case QCamera::CameraError: {
QMessageBox::warning(this, "Camera error", "General camera error");
break;
}
case QCamera::NotReadyToCaptureError: {
QMessageBox::warning(this, "Camera error", "Camera not ready to capture image");
break;
}
case QCamera::InvalidRequestError: {
QMessageBox::warning(this, "Camera error", "Invalid request");
break;
}
case QCamera::ServiceMissingError: {
QMessageBox::warning(this, "Camera error", "Service missing");
break;
}
case QCamera::NotSupportedFeatureError: {
QMessageBox::warning(this, "Camera error", "Not supported feature");
break;
}
default:
break;
};
}

Classes

  • QCamera
  • QVideoWidget

Reference links

--skumar_rao 03:02, 28 March 2010 (UTC)

138 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.

×