×
Namespaces

Variants
Actions
(Difference between revisions)

Display camera preview using Qt Mobility

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan")
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetadata)
Line 1: Line 1:
 +
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20100328
 +
|author= [[User:Skumar rao]]
 +
}}
 
[[Category:Qt Mobility]]
 
[[Category:Qt Mobility]]
 
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"  
 
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"  
Line 21: Line 43:
 
{{Warning| Camera API has been removed from Mobility. It was in the tech preview and maybe it will be added again later on.}}
 
{{Warning| Camera API has been removed from Mobility. It was in the tech preview and maybe it will be added again later on.}}
  
{{Tip| Read this article before moving forward: [[Setting up environment for Qt Mobility API]]}}
+
{{Tip| Read this article before moving forward: [[Archived:Setting up environment for Qt Mobility API]]}}
  
 
== Overview ==  
 
== Overview ==  

Revision as of 09:09, 20 July 2012

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: skumar_rao (28 Mar 2010)
Last edited: hamishwillee (20 Jul 2012)
ID Creation date 28th Mar 2010
Platform S60 5th Edition Tested on devices Nokia N97 Mini
Category Qt Subcategory Qt Mobility API


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

Warning.pngWarning: Camera API has been removed from Mobility. It was in the tech preview and maybe it will be added again later on.

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

Contents

Overview

Display Camera Preview on Widget using Qt Mobility APIs

Project configuration file (.Pro file)

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

Header File

#include <qcamera.h>
#include <qvideowidget.h>
#include <qstackedwidget.h>
 
class CameraApp : public 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

#include <qmessagebox.h>
#include <qgridlayout.h>
 
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

134 page views in the last 30 days.
×