Home · All Classes · All Functions ·

Quickstart Example

Files:

The following steps outline how to make a simple "hello world" like application that uses Qt Mobility. It is assumed that Qt Mobility has been successfully built and environment variables have been set as per Installation Guide.

One can start using Qt Mobility with 3 simple steps.

  1. Include the appropriate headers
  2. Use the QtMobility namespace
  3. Declare the usage of Qt Mobility and appropriate domain(s) in the project(.pro) file

Steps 1 and 2 are shown in the example below:

    #include <QApplication>
    #include <QLabel>

    #ifdef Q_OS_SYMBIAN
    #include <qsysteminfo.h>
    #else
    #include <QSystemInfo> //(1)
    #endif
    using namespace QtMobility; //(2)

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QSystemInfo s;
        QLabel *label = new QLabel(QObject::tr("hello ").append(s.currentCountryCode()));
        label->show();
        label->resize(100,30);
        return app.exec();
    }

Here we are using the QSystemInfo headers to print out the system's current country code. All the domain APIs are wrapped within the QtMobility namespace and thus developers either need to declare using namespace QtMobility or qualify their symbols e.g. QtMobility::QSystemInfo s. (Note: If you are on the Symbian platform you will need to define the actual header file, in this case <qsysteminfo.h> rather than using the standard header form <QSystemInfo>, this is a known bug that is to be addressed in a future release)

In step 3, to specify that our project is using System Information we declare in the project file:

    CONFIG += mobility
    MOBILITY += systeminfo

Here we've declared that the application uses Qt Mobility and that we are using the System Information domain. (Internally this results in qmake setting up include and library search paths. See mobility.prf for details to see what those paths are, it is copied into the mkspecs/features directory of Qt's install path)

The following table lists the domains and the corresponding values that can be assigned to MOBILITY.

DomainValue
Bearer Managementbearer
Contactscontacts
Locationlocation
Multimediamultimedia
Messagingmessaging
Publish And Subscribepublishsubscribe
Service Frameworkserviceframework
System Informationsysteminfo
Versitversit

And we're done. If you are using the command line simply enter:

    qmake
    make

to generate the executable which can then be run.

To build for the symbian emulator run:

    qmake
    make

To build a symbian sis package:

    qmake
    make release-gcce
    createpackage quickstart_template.pkg release-gcce


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Mobility Project 1.0.0 (Technology Preview)