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. Thanks for all your past and future contributions.

How to get list of Time Zones in Qt Maemo application

From Wiki
Jump to: navigation, search

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}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Tested with
Devices(s): Nokia N900
Platform(s): Maemo
Keywords: TimeZone
Created: Avis (25 Nov 2009)
Last edited: lpvalente (13 Apr 2013)



This example shows how to get list of Time Zones in Qt Maemo application using GTK functions (as there are no Qt classes for this operation)

Project .pro file

// Maemo specific config
maemo5 {
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0 libcityinfo0-0

Packing in DEB - control file

// in source section add for Build-depends line
libtime-dev, libcityinfo-dev


#include <cityinfo.h>
#include <clockd/libtime.h>


// get the refence to QComboBox for filling
void SampleWisget::fillTimeZones(QComboBox* &aBox)
int ret = 0;
char current_tz[32];
// get current Time Zone
ret = time_get_timezone(&current_tz[0],32);
// convert from char* to QString
QString defTZ = QString::fromUtf8(current_tz);
// clear the list
// get list of Cities
Cityinfo **cities = cityinfo_get_all();
// cycle throug all Cities
for (int i = 0; cities && cities[i]; ++i) {
// get next city params
QString name = QString::fromUtf8(cityinfo_get_name(cities[i]));
QString country = QString::fromUtf8(cityinfo_get_country(cities[i]));
QString zone = ":" + QString::fromUtf8(cityinfo_get_zone(cities[i]));
QString timeoffset;
QString sign;
// get time offset from UTC for current city
int offset = time_get_utc_offset(cityinfo_get_zone(cities[i]));
// define sign for offset
if (offset > 0)
sign = "";
sign = "+";
// some offset not rounded to hours, so check this and form QString in form
// City Name + Country + Time Offset
if((offset % 3600)==0)
timeoffset = QString("%2, %1, (UTC %3)").arg(name).arg(country).arg(sign+QString::number(-offset/3600));
timeoffset = QString("%2, %1, (UTC %3:%4)").arg(name).arg(country).arg(sign+QString::number(-offset/3600)).arg("30");
// add new record to list (formed QString - to text field, and real offset in seconds - to User field)
// if current city time offset is equal to those got from system - store it's offset
if (zone == defTZ)
defTZ = timeoffset;
// free unneded city list
// sort the list alphabetically (by the City Name)
// loking for stored time offest in sorted list
int k = aBox->findText(defTZ);
// setting list position to the city with time offset, which we get in the beginning


The Qt widget with QComboBox filled with TimeZones.

--Avis 9:28, 30 November 2010 (UTC)

This page was last modified on 13 April 2013, at 21:35.
62 page views in the last 30 days.