Camera Key Event Disposal in Qt on Symbian
On Symbian the camera hardware key launches the native camera app. This article explains how to dispose of the camera key event so that the key can be used to take pictures using your own Qt app.
Note: This is an entry in the PureView Imaging Competition 2012Q2
Article Metadata
Compatibility
Platform(s): Qt 4.6 and later
Article
Keywords: Camera
Created: r60600
(08 May 2012)
Last edited: hamishwillee
(11 Oct 2012)
Introduction
Mobile users often use the camera key when they capture image or video. So the developers must add key event disposal in their Qt application.
After Qt 4.7,there are 2 enumerations in the qnamespace.h: Qt::Key_Camera and Qt::Key_CameraFocus
The usual camera key event disposal way is
void Camera::keyPressEvent(QKeyEvent * event)
{
if (event->isAutoRepeat())
return;
switch (event->key()) {
#if QT_VERSION >= 0x040700
case Qt::Key_CameraFocus:
//focus operation
event->accept();
break;
case Qt::Key_Camera:
//capture operation
event->accept();
break;
#endif
default:
QMainWindow::keyPressEvent(event);
}
}
void Camera::keyReleaseEvent(QKeyEvent * event)
{
if (event->isAutoRepeat())
return;
switch (event->key()) {
#if QT_VERSION >= 0x040700
case Qt::Key_CameraFocus:
//Un-focus operation
break;
#endif
default:
QMainWindow::keyReleaseEvent(event);
}
}
Last, application had better add a listener to dispose Symbian camera key event for Symbian device like this:
#include "camerakeyevent_symbian.h"
...
#if defined (Q_OS_SYMBIAN)
QApplication::setGraphicsSystem("raster");
QApplication app(argc, argv); // lock orientation before constructing camera
CAknAppUi* appUi = dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi());
if(appUi){QT_TRAP_THROWING(appUi ->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape));}
...
new QSymbianCameraKeyListener(&camera);
#endif

