Couple days ago I posted a video example of the MVC-model running on N900. Someone asked me that how did I do that thing and I believe that the question was about how to react on orientation changes in Qt application on N900. If you are not familiar with Qt D-Bus Module it’s worth to read the documentation from here first.
The orientation changes in N900 can be listened through a dbus interface. Doing that is pretty straight forward and it requires only couple lines of code:
MyReceiverClass * receiver = new MyReceiverClass(this); QDBusConnection systemBus = QDBusConnection::systemBus(); systemBus.connect("com.nokia.mce", "/com/nokia/mce/signal", "com.nokia.mce.signal", "sig_device_orientation_ind", receiver, SLOT(orientationChanged(QString)));
In the code snipplet above I have a basic QObject based class “MyReceiverClass” which have a slot called “orientationChanged(QString)”. This slot takes a QString as an argument. When a signal called “sig_device_orientation_ind” has been send via D-Bus, the receiver’s slot will be called automatically and it can have one of the ”landscape” or “portrait” strings as a literal value. The rest of is up to the developer to decide what to do in the slot.
That’s it. Simple, isn’t it?