Documentation/Maemo 5 Developer Guide/Development Environment/Maemo Programming Environments/Using Maemo 5 specific APIs in Qt application

Introduction

This section explains how to use the accelerometer D-Bus interface in a Maemo 5 Qt application.

The following code examples are used in this section:

D-Bus interface

It is up to each application how to organize interactions with the MCE orientation interface. In some cases catching orientation signal can be enough, but if, e.g., more frequent updates are needed, you might want to use method calls, as demonstrated in our example. We've moved D-Bus related functionality and orientation based calculations to a separate library that implements `DeviceOrientationNotifier' class. Our notifier asks MCE about orientation parameters with a certain period,

void DeviceOrientationNotifier::timerEvent(QTimerEvent *)
{
  QDBusMessage msg = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET);
  bool sent = QDBusConnection::systemBus().callWithCallback(msg, this, SLOT(mceOrientationSlot(QString, QString, QString, int, int, int)));
}

processes answers in `mceOrientationSlot', and emits data needed by the application with the following signal.

void deviceOrientation(qreal pitch, qreal roll);

Example application

We've modified one of Qt4 Examples in order to show how device orientation can be used. In our case pitch and roll are scene's characteristics, so we've implemented a `SceneTuner', whose slot can be connected to an appropriate signal in order to setup these scene properties.

DeviceOrientationNotifier notifier(100);
SceneTuner tuner(&scene, TimerInterval);
QObject::connect(&notifier, SIGNAL(deviceOrientation(qreal, qreal)), &tuner, SLOT(setProps(qreal, qreal)));

Based on that each mouse can take into account the gravity effect, see `Mouse::advance' for details.