Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Using Notification API in GPS based application

From Wiki
Jump to: navigation, search
Article Metadata
Created: aj4mobile (06 Mar 2011)
Last edited: hamishwillee (21 Nov 2013)

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Notification API deprecated.



Qt, the cross-platform application and UI framework, has newly introduced Notifications API, a striking feature which helps in adding real-time push notifications. Notifications API is highly efficient as it delivers light-weight notifications optimizing bandwidth and battery usage. Mobile application development is in its revolutionary stage now; server-initiated push messages to the mobile client are an inevitable factor here, which has been employed by Qt in the new beta release. Notifications API enables clients to obtain instantaneous notifications for email, facebook, twitter, weather updates, stock updates, etc even when the applications are not active. In this article, I hereby elucidate yet another applicability of Notification API using GPS.

Goals and objectives:

To utilize Notifications API and develop a real-time sticky application within hours with minimal development effort.

Problem statement:

Situations arise when people need to be traced in order to find out their exact location in emergencies. Such situations can be met by introducing a GPS application using Notifications API which helps to track a person who is registered to the server by another person who is also registered and connected with the former. This helps in circumstances where the former is not in a position to respond, but needs to be traced where he/she is.


A client side application is developed which retrieves latitudes/longitudes and receives messages from the back end server. The notifications support can be provided by using Notifications Qt API. QT Mobility Location API can be used to get latitude & longitude. Develop a back end server which enables user registration, authentication, sending message to the requested user. This server sends the message to the mobile by using Notifications Service API. The Notification Service API provides access to the Notification Server through an HTTP REST interface.

Why Qt:

Notification implementation using a third party SMS gateway server to send message to mobile is a costly process.

The push mechanism used in Blackberry phones using Blackberry Enterprise Service is highly expensive.

Even though Apple push notification service works similar to Qt, the ease with which development can be done in Qt Quick makes it an all-time favorite. Moreover, it does not need a specific platform for development unlike the iPhone development which can be done only in Mac environment.

Android also lags behind Qt Quick in developmental ease and it is not available universally.

Resource requirement:

- A mobile application which supports Qt SDK 1.1 (Beta)

- Internet connectivity in the mobile

- A public IP server machine

- A developer

How this app works:

This application helps registered clients to track their geographical positions even if they are not in a situation to respond to messages. A client who is registered to the server can access other clients who are also linked with the server and who have enabled tracing by the former. When the client requests for tracking of another client, the server sends a message via Notification API to the latter’s phone, and the latter responds by sending the current longitudinal and latitudinal position. This message hits the server again, and the server pushes it to the former who initiated the request. The positions are evoked in a map in the former’s mobile, denoting the exact geographical position of the latter. Any registered user is entitled to enable or disable the tracking facility according to their wish.

A Guide towards implementation of the application:

Implementing the project is quite simple since all the needed resources are available in Nokia Developer and Qt Nokia website itself.

Client Application:

The client application consists of three modules viz. UI, latitudes and longitudes retrieval and notification listener.

The UI for the mobile application can be easily created using QT Quick. Many samples are available which comes along with SDK. The developer shall cull out desired samples and develop accordingly.

The latitude and longitudes retrieval source code is given here

void MainWindow::startGPS()
// Obtain the location data source if it is not obtained already
if (!locationDataSource)
locationDataSource =
if (locationDataSource)
// Whenever the location data source signals that the current
// position is updated, the positionUpdated function is called.
// Start listening for position updates
} else {
// Not able to obtain the location data source
// TODO: Error handling
} else {
// Start listening for position updates
void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo)
if (geoPositionInfo.isValid())
// Stop regular position updates, because a valid position has been
// obtained
// Get the current location as latitude and longitude
QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
qreal latitude = geoCoordinate.latitude();
qreal longitude = geoCoordinate.longitude();
// Fetch the map using the display size and the coordinates
QUrl url = createGoogleMapURL(size(), latitude, longitude);
webView->stop(); // Stop the ongoing request
webView->load(url); // Load the Google Map
QUrl MainWindow::createGoogleMapURL(const QSize& size, qreal latitude,qreal longitude)
QString::number(latitude), QString::number(longitude),
QString::number(size.width()), QString::number(size.height())));
return url;
Instantiate QWebView() as below and invoke startGPS() from your application module.
webView = new QWebView(this);
// Start the GPS

It can be referred in the link: The file shall be downloaded, opened in Qt SDK 1.1 (Beta), the code is copied and appended to the project.

For registering & unregistering the application for the notification

void NotificationExample::registerApplication()
// Register to Notifications
iTextConsole->append("Registering to Notifications ...");
void NotificationExample::unregisterApplication()
// Unregister from Notifications
iTextConsole->append("Unregistering from Notifications...");

The code for receiving notification message in the application is given below. This can be customized in such a way that on receiving the notification message, the application invokes the latitudinal & longitudinal values as explained above.

void NotificationExample::received(QObject* aNotification)
// Casting the QObject to OviNotificationMessage to gain access
// to all its members.
OviNotificationMessage* notification =
// Show the received notification in the screen
OviNotificationPayload* payload = static_cast<OviNotificationPayload*>(notification->payload());
iTextConsole->setText("Notification received!");
iTextConsole->append("Application " + notification->senderInformation()
+ " of the service "+notification->from()+ " service sent: \n"
+ "'" + payload->dataString() + "'");
// Printing out the notification details in text console. Optional.
iTextConsole->append("Notification received.");
iTextConsole->append("Notification was sent at " + notification->timestamp());
if (!payload->type().isEmpty())
iTextConsole->append("Payload type was set to " + payload->type());
if (!payload->encoding().isEmpty())
iTextConsole->append("Payload was encoded in " + payload->encoding());
delete notification;

Back end server application:

The developer can develop a simple server side application in his choice of platform. The server sends message to mobile via Notifications API.


There were many social networking sites which came into being before Facebook. But none of them were as successful as Facebook. This shows that the time of introduction doesn't matter, the uniqueness in expression of ideas is what that matters. Similarly, the above application developed using Qt framework and Notifications API shall stretch its wings beyond the horizons.


This page was last modified on 21 November 2013, at 09:57.
118 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.