×
Namespaces

Variants
Actions
Revision as of 05:44, 25 November 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Earthquake-Reporting application for Qt and Windows Phone

From Nokia Developer Wiki
Jump to: navigation, search
WP Metro Icon Porting.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code ExampleTested with
SDK: Windows Phone SDK 8.0, Qt SDK 1.2
Devices(s): Nokia Lumia 820, Lumia 920
CompatibilityArticle
Created: somnathbanik (15 Apr 2012)
Last edited: hamishwillee (25 Nov 2013)

Contents

Introduction

This article demonstrates how to implement the Qt Quick Earthquake-Reporting application with XmlListModel application on Windows Phone 7. The data is obtained from the U.S. Geological Survey and renders the result as a list of earthquake events using a ListBox.

Earthquake Reporting Application

Implementation

Qt

The article Earthquake-Reporting application with XmlListModel explains how the app is implemented in Qt Quick using the XmlListModel QML Element that lets you fetch and parse RSS feeds using only XPath queries

WP7

First create an empty Windows Phone project. We add a ListBox to display the data to the left of the screen.

<StackPanel Orientation="Horizontal"  HorizontalAlignment="Left" VerticalAlignment="Top"  Width="350" >                
<ListBox Name ="listboxData" Margin="0,0,-12,0" Loaded="Menu_Loaded"
SelectionChanged="listboxData_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<StackPanel Width="350" Margin="12,-9,0,0">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}"/>
<TextBlock Text="{Binding PubDate}" TextWrapping="Wrap" Margin="11,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
 
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
 
</StackPanel>

We download the data, parse it and bind it to the ListBox.

XElement xmlData = XElement.Parse(e.Result);
XNamespace geo = "http://www.w3.org/2003/01/geo/wgs84_pos#";
XNamespace dc = "http://purl.org/dc/elements/1.1/";
listboxData.Items.Clear();
 
foreach (var item in xmlData.Descendants("item"))
{
 
RssData rssData = new RssData();
rssData.Title = (string)item.Element("title").Value;
rssData.PubDate = (string)item.Element("pubDate").Value;
rssData.lat = (string)item.Element(geo + "lat").Value;
rssData.lng = (string)item.Element(geo + "long").Value;
 
listboxData.Items.Add(rssData);
}

When user clicks on any of the list items we display the detail information to the right of the screen.

<Canvas Width="350" Height="313" VerticalAlignment="Top" HorizontalAlignment="Right">
<TextBlock Canvas.Left="10" Canvas.Top="141" Height="30" Name="textBlock1" Text="Lat : " />
<TextBlock Canvas.Left="86" Canvas.Top="141" Height="30" Name="canLat" Text="" TextWrapping="Wrap" />
<TextBlock Canvas.Left="10" Canvas.Top="201" Height="30" Name="textBlock3" Text="Long : " />
<TextBlock Canvas.Left="86" Canvas.Top="201" Height="30" Name="canLng" TextWrapping="Wrap" Text="" />
<TextBlock Canvas.Left="10" Canvas.Top="21" Height="66" Name="canTitle" Text="" Width="323" TextWrapping="Wrap" />
<TextBlock Canvas.Left="10" Canvas.Top="89" Height="40" Name="canSubTitle" Text="" Width="323" TextWrapping="Wrap" />
</Canvas>

That's it.

Source Code

This page was last modified on 25 November 2013, at 05:44.
49 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.

×