When you are developing with Qt on Maemo you might want to minimize or detect minimization of your application to the dashboard. Qt lacks clean functions for these use cases, but thankfully it’s still very easy to accomplish them.

Minimizing the application

First of all, to minimize your application you’ll need to add the following CONFIG line to your project file (the .pro file):

maemo5 {
    CONFIG += qdbus
}

Then, in your .cpp or .h file, you’ll need to include the QtDBus headers:

#ifdef Q_WS_MAEMO_5
#include <QtDBus/QtDBus>
#endif

You may of course skip the #ifdef statements if you’d like DBus for other systems as well, but here I’d like to make this exception only for Maemo. Now, anywhere in your application you may add the following lines to minimize to Maemo’s dashboard:

QDBusConnection connection = QDBusConnection::sessionBus();
QDBusMessage message = QDBusMessage::createSignal("/","com.nokia.hildon_desktop","exit_app_view");
connection.send(message);

This could for example be placed inside a signal that is emitted when the users pushes a dashboard button.

Detecting minimization

If you’d like to detect if the user pressed CTRL + Backspace or any other button to minimize the application, you may do so by adding a changeEvent function to your top-most window. Inside you check the event->type() against QEvent::ActivationChange and test the isActiveWindow() at the same time. Here is an example from the Nanoparticles game:

void GameView::changeEvent(QEvent *event) {
#ifdef Q_WS_MAEMO_5
    if(event->type()==QEvent::ActivationChange) {
        if(!isActiveWindow()) {
            gameScene.pauseGame();
        }
    }
#endif
}

Whenever the game is minimized now, the game is automatically paused to avoid background rendering. The game uses OpenGL to render everything, so this saves the battery drastically.

Enjoy your minimized applications!