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 accelerometer D-Bus interface in Maemo 5 Qt application.

The following code examples are used in this section:

D-Bus interface

It's up to each application how to organize interactions with 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, that demonstrated in our example. We've moved D-Bus related functionality and orientation based calculations to separate library, that implements `DeviceOrientationNotifier' class. Our notifier asks MCE about orientation parameters with certain period,

void DeviceOrientationNotifier::mceOrientationCall()
{
  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 application with 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 `SceneTuner', that's slot can be connected to appropriate signal in order to setup these scene's properties.

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

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