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


Hamishwillee - Planning on finishing this for Tuesday?
If so, please complete the article, and when you are done remove the Draft category.
Regards
Hhamishwillee 08:12, 25 May 2012 (EEST)
Chintandave er - Pls finish it. !
Hi, First thanks for the article.
Still This article seems uncompleted. Please update the article with some more description. I also suggest you to add some screenshot of this code output. so other can easily understand.
Thanks,
Chintan Dave.Chintandave er 11:41, 9 June 2012 (EEST)
Hamishwillee - Hamishwillee - I agree with Chintan
I've added an abstract explaining what this article is actually for - intercepting the camera hardware key in Symbian so that it can be used for taking photos - otherwise pressing the key will just launch the native app.
I think the idea of the article is good, but the explanation is poor. This could be improved by adding a working code sample so people could at least read the code. For example, its not clear what "QSymbianCameraKeyListener" does and where it comes from.
In general the best way to start something like this is to have a clear statement of what it is your code is going to do. So something like "This code adds a Qt Key event listener to the app and then implements the keyPressEvent to detect the camera hardware button being pressed. This event is then "accepted" which prevents it being passed to the rest of the system to be handled (in which case other code would have launched the camera).
Regards Hamish