Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 8224

qt4-doc-4.8.7-26.2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- trafficinfo.qdoc -->
  <title>Qt 4.8: TrafficInfo Example</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="all-examples.html">Examples</a></li>
<li>TrafficInfo Example</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#overview">Overview</a></li>
<li class="level1"><a href="#retrieving-the-data">Retrieving the Data</a></li>
</ul>
</div>
<h1 class="title">TrafficInfo Example</h1>
<span class="subtitle"></span>
<!-- $$$xmlpatterns/trafficinfo-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="xmlpatterns-trafficinfo-mainwindow-cpp.html">xmlpatterns/trafficinfo/mainwindow.cpp</a></li>
<li><a href="xmlpatterns-trafficinfo-mainwindow-h.html">xmlpatterns/trafficinfo/mainwindow.h</a></li>
<li><a href="xmlpatterns-trafficinfo-stationdialog-cpp.html">xmlpatterns/trafficinfo/stationdialog.cpp</a></li>
<li><a href="xmlpatterns-trafficinfo-stationdialog-h.html">xmlpatterns/trafficinfo/stationdialog.h</a></li>
<li><a href="xmlpatterns-trafficinfo-stationdialog-ui.html">xmlpatterns/trafficinfo/stationdialog.ui</a></li>
<li><a href="xmlpatterns-trafficinfo-stationquery-cpp.html">xmlpatterns/trafficinfo/stationquery.cpp</a></li>
<li><a href="xmlpatterns-trafficinfo-stationquery-h.html">xmlpatterns/trafficinfo/stationquery.h</a></li>
<li><a href="xmlpatterns-trafficinfo-timequery-cpp.html">xmlpatterns/trafficinfo/timequery.cpp</a></li>
<li><a href="xmlpatterns-trafficinfo-timequery-h.html">xmlpatterns/trafficinfo/timequery.h</a></li>
<li><a href="xmlpatterns-trafficinfo-main-cpp.html">xmlpatterns/trafficinfo/main.cpp</a></li>
<li><a href="xmlpatterns-trafficinfo-trafficinfo-pro.html">xmlpatterns/trafficinfo/trafficinfo.pro</a></li>
</ul>
<p>The Traffic Info example shows how <a href="xmlprocessing.html">XQuery</a> can be used extract information from WML documents provided by a WAP service.<a name="overview"></a>
<h2>Overview</h2>
<p>The WAP service used in this example is <a href="http://wap.trafikanten.no">wap.trafikanten.no</a> that is run by the Norwegian governmental agency for public transport in Oslo. The service provides real time information about the departure of busses, trams and undergrounds for every station in the city area.</p>
<p>This example application displays the departure information for a specific station and provides the feature to filter for a special bus or tram line.</p>
<p class="centerAlign"><img src="images/trafficinfo-example.png" alt="" /></p><a name="retrieving-the-data"></a>
<h2>Retrieving the Data</h2>
<p>Without the knowledge of <a href="xmlprocessing.html">XQuery</a>, one would use <a href="qnetworkaccessmanager.html">QNetworkAccessManager</a> to query the WML document from the WAP service and then using the QDom classes or <a href="qxmlstreamreader.html">QXmlStreamReader</a> classes to iterate over the document and extract the needed information. However this approach results in a lot of glue code and consumes valuable developer time, so we are looking for something that can access XML documents locally or over the network and extract data according to given filter rules. That's the point where <a href="xmlprocessing.html">XQuery</a> enters the stage!</p>
<p>If we want to know when the underground number 6 in direction &Aring;<tt></tt>sjordet is passing the underground station in Nydalen on November 14th 2008 after 1pm, we use the following URL:</p>
<p><tt>http://wap.trafikanten.no/F.asp?f=03012130&amp;t=13&amp;m=00&amp;d=14.11.2008&amp;start=1</tt></p>
<p>The parameters have the following meanings:</p>
<ul>
<li><i>f</i> The unique station ID of Nydalen.</li>
<li><i>t</i> The hour in 0-23 format.</li>
<li><i>m</i> The minute in 0-59 format.</li>
<li><i>d</i> The date in dd.mm.yyyy format.</li>
<li><i>start</i> Not interesting for our use but should be passed.</li>
</ul>
<p>As a result we get the following document:</p>
<pre class="cpp"> &lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
 &lt;!DOCTYPE wml PUBLIC &quot;-//WAPFORUM//DTD WML 1.1//EN&quot; &quot;http://www.wapforum.org/DTD/wml_1.1.xml&quot;&gt;
 &lt;wml&gt;
 &lt;template&gt;
     &lt;do type=&quot;prev&quot; name=&quot;b&quot; label=&quot;Tilbake&quot;&gt;&lt;prev/&gt;&lt;/do&gt;
     &lt;do type=&quot;options&quot; name=&quot;n&quot; label=&quot;Nytt sk&quot;&gt;&lt;go href=&quot;velkommen.wml&quot;/&gt;&lt;/do&gt;
 &lt;/template&gt;
 &lt;card id=&quot;Liste&quot; title=&quot;Trafikanten&quot;&gt;
 &lt;p&gt;
 &lt;small&gt;
 Fra Nydalen [T-bane]:&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3011030&amp;amp;t=21832&amp;amp;l=4&amp;amp;Start=1&quot;&gt;13.00&lt;/a&gt;
      4 Bergkrystallen [T-bane]&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3012585&amp;amp;t=22543&amp;amp;l=6&amp;amp;Start=1&quot;&gt;13.05&lt;/a&gt;
      6 sjordet&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3011730&amp;amp;t=22264&amp;amp;l=5&amp;amp;Start=1&quot;&gt;13.09&lt;/a&gt;
      5 Vestli [T-bane]&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3012120&amp;amp;t=22080&amp;amp;l=5&amp;amp;Start=1&quot;&gt;13.13&lt;/a&gt;
      5 Storo [T-bane]&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3011030&amp;amp;t=21831&amp;amp;l=4&amp;amp;Start=1&quot;&gt;13.15&lt;/a&gt;
      4 Bergkrystallen [T-bane]&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3012585&amp;amp;t=22542&amp;amp;l=6&amp;amp;Start=1&quot;&gt;13.20&lt;/a&gt;
      6 sjordet&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3011730&amp;amp;t=22263&amp;amp;l=5&amp;amp;Start=1&quot;&gt;13.24&lt;/a&gt;
      5 Vestli [T-bane]&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3012120&amp;amp;t=22079&amp;amp;l=5&amp;amp;Start=1&quot;&gt;13.28&lt;/a&gt;
      5 Storo [T-bane]&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3011030&amp;amp;t=21830&amp;amp;l=4&amp;amp;Start=1&quot;&gt;13.30&lt;/a&gt;
      4 Bergkrystallen [T-bane]&lt;br /&gt;

     &lt;a href=&quot;Rute.asp?d=3012585&amp;amp;t=22541&amp;amp;l=6&amp;amp;Start=1&quot;&gt;13.35&lt;/a&gt;
      6 sjordet&lt;br /&gt;

     &lt;br /&gt;
     &lt;a title=&quot;Neste 10&quot; href=&quot;F.asp?f=03012130&amp;amp;t=13&amp;amp;m=35&amp;amp;d=14.11.2008&amp;amp;Start=11&quot;&gt;Neste 10 avganger&lt;/a&gt;

 &lt;br/&gt;
 &lt;a href=&quot;F.asp?f=03012130&amp;amp;t=14&amp;amp;d=14.11.2008&amp;amp;Start=1&quot;&gt;Neste timeintervall&lt;/a&gt;
 &lt;br/&gt;
 &lt;a href=&quot;F.asp?f=03012130&amp;amp;t=12&amp;amp;d=14.11.2008&amp;amp;Start=1&quot;&gt;Forrige timeintervall&lt;/a&gt;
 &lt;br/&gt;
 &lt;a href=&quot;Velkommen.wml&quot;&gt;&quot;Nytt sk&quot;&lt;/a&gt;
 &lt;br/&gt;
 &lt;/small&gt;
 &lt;/p&gt;
 &lt;/card&gt;
 &lt;/wml&gt;</pre>
<p>So for every departure we have a <tt>&lt;a&gt;</tt> tag that contains the time as a text element, and the following text element contains the line number and direction.</p>
<p>To encapsulate the <a href="xmlprocessing.html">XQuery</a> code in the example application, we create a custom <tt>TimeQuery</tt> class. This provides the <tt>queryInternal()</tt> function that takes a station ID and date/time as input and returns the list of times and directions:</p>
<pre class="cpp"> TimeInformation<span class="operator">::</span>List TimeQuery<span class="operator">::</span>queryInternal(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>stationId<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qdatetime.html">QDateTime</a></span> <span class="operator">&amp;</span>dateTime)
 {
     <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> timesQueryUrl <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">&quot;doc('http://wap.trafikanten.no/F.asp?f=%1&amp;amp;t=%2&amp;amp;m=%3&amp;amp;d=%4&amp;amp;start=1')/wml/card/p/small/a[fn:starts-with(@href, 'Rute')]/string()&quot;</span>)
                                          <span class="operator">.</span>arg(stationId)
                                          <span class="operator">.</span>arg(dateTime<span class="operator">.</span>time()<span class="operator">.</span>hour())
                                          <span class="operator">.</span>arg(dateTime<span class="operator">.</span>time()<span class="operator">.</span>minute())
                                          <span class="operator">.</span>arg(dateTime<span class="operator">.</span>toString(<span class="string">&quot;dd.MM.yyyy&quot;</span>));
     <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> directionsQueryUrl <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">&quot;doc('http://wap.trafikanten.no/F.asp?f=%1&amp;amp;t=%2&amp;amp;m=%3&amp;amp;d=%4&amp;amp;start=1')/wml/card/p/small/text()[matches(., '[0-9].*')]/string()&quot;</span>)
                                               <span class="operator">.</span>arg(stationId)
                                               <span class="operator">.</span>arg(dateTime<span class="operator">.</span>time()<span class="operator">.</span>hour())
                                               <span class="operator">.</span>arg(dateTime<span class="operator">.</span>time()<span class="operator">.</span>minute())
                                               <span class="operator">.</span>arg(dateTime<span class="operator">.</span>toString(<span class="string">&quot;dd.MM.yyyy&quot;</span>));

     <span class="type"><a href="qstringlist.html">QStringList</a></span> times;
     <span class="type"><a href="qstringlist.html">QStringList</a></span> directions;

     <span class="type"><a href="qxmlquery.html">QXmlQuery</a></span> query;
     query<span class="operator">.</span>setQuery(timesQueryUrl);
     query<span class="operator">.</span>evaluateTo(<span class="operator">&amp;</span>times);

     query<span class="operator">.</span>setQuery(directionsQueryUrl);
     query<span class="operator">.</span>evaluateTo(<span class="operator">&amp;</span>directions);

     <span class="keyword">if</span> (times<span class="operator">.</span>count() <span class="operator">!</span><span class="operator">=</span> directions<span class="operator">.</span>count()) <span class="comment">// something went wrong...</span>
         <span class="keyword">return</span> TimeInformation<span class="operator">::</span>List();

     TimeInformation<span class="operator">::</span>List information;
     <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> times<span class="operator">.</span>count(); <span class="operator">+</span><span class="operator">+</span>i)
         information<span class="operator">.</span>append(TimeInformation(times<span class="operator">.</span>at(i)<span class="operator">.</span>simplified()<span class="operator">,</span> directions<span class="operator">.</span>at(i)<span class="operator">.</span>simplified()));

     <span class="keyword">return</span> information;
 }</pre>
<p>The first lines of this function synthesize the <a href="xmlprocessing.html">XQuery</a> strings that fetch the document and extract the data. For better readability, two separated queries are used here: the first one fetches the times and the second fetches the line numbers and directions.</p>
<p>The <tt>doc()</tt> <a href="xmlprocessing.html">XQuery</a> method opens a local or remote XML document and returns it, so the <tt>/wml/card/p/small/</tt> statement behind it selects all XML nodes that can be reached by the path, <tt>wml</tt> &rarr; <tt>card</tt> &rarr; <tt>p</tt> &rarr; <tt>small</tt>. Now we are on the node that contains all the XML nodes we are interested in.</p>
<p>In the first query we select all <tt>a</tt> nodes that have a <tt>href</tt> attribute starting with the string &quot;Rute&quot; and return the text of these nodes.</p>
<p>In the second query we select all text nodes that are children of the <tt>small</tt> node which start with a number. These two queries are passed to the <a href="qxmlquery.html">QXmlQuery</a> instance and are evaluated to string lists. After some sanity checking, we have collected all the information we need.</p>
<p>In the section above we have seen that an unique station ID must be passed as an argument to the URL for retrieving the time, so how to find out which is the right station ID to use? The WAP service provides a page for that as well, so the URL</p>
<p><tt>http://wap.trafikanten.no/FromLink1.asp?fra=Nydalen</tt></p>
<p>will return the following document:</p>
<pre class="cpp"> &lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
 &lt;!DOCTYPE wml PUBLIC &quot;-//WAPFORUM//DTD WML 1.1//EN&quot; &quot;http://www.wapforum.org/DTD/wml_1.1.xml&quot;&gt;
 &lt;wml&gt;
 &lt;template&gt;
     &lt;do type=&quot;prev&quot; name=&quot;b&quot; label=&quot;Tilbake&quot;&gt;&lt;prev/&gt;&lt;/do&gt;
     &lt;do type=&quot;options&quot; label=&quot;Nytt sk&quot;&gt;&lt;go href=&quot;velkommen.wml&quot;/&gt;&lt;/do&gt;
 &lt;/template&gt;
 &lt;card id=&quot;Liste&quot; title=&quot;Trafikanten&quot;&gt;
 &lt;p&gt;
 &lt;small&gt;
 Velg stoppsted: &lt;br /&gt;

    &lt;a title=&quot;Velg&quot; href=&quot;DateLink.asp?fra=05280320&quot;&gt;Nydalen (stre Toten) (-T)&lt;/a&gt;&lt;br /&gt;

    &lt;a title=&quot;Velg&quot; href=&quot;DateLink.asp?fra=03012126&quot;&gt;Nydalen st. (i Store ringvei) (OSL)&lt;/a&gt;&lt;br /&gt;

    &lt;a title=&quot;Velg&quot; href=&quot;DateLink.asp?fra=03012131&quot;&gt;Nydalen T [buss] (OSL)&lt;/a&gt;&lt;br /&gt;

    &lt;a title=&quot;Velg&quot; href=&quot;DateLink.asp?fra=03012130&quot;&gt;Nydalen [T-bane] (OSL)&lt;/a&gt;&lt;br /&gt;

    &lt;a title=&quot;Velg&quot; href=&quot;DateLink.asp?fra=03012125&quot;&gt;Nydalen [tog] (OSL)&lt;/a&gt;&lt;br /&gt;

 &lt;br/&gt;
 &lt;a title=&quot;Nytt sk&quot; href=&quot;Velkommen.wml&quot;&gt;&quot;Nytt sk&quot;&lt;/a&gt;
 &lt;br/&gt;
 &lt;/small&gt;
 &lt;/p&gt;
 &lt;/card&gt;
 &lt;/wml&gt;</pre>
<p>The names of the available stations are listed as separate text elements and the station ID is part of the <tt>href</tt> attribute of the parent <tt>a</tt> (anchor) element. In our example, the <tt>StationQuery</tt> class encapsulates the action of querying the stations that match the given name pattern with the following code:</p>
<pre class="cpp"> StationInformation<span class="operator">::</span>List StationQuery<span class="operator">::</span>query(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>name)
 {
     <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> stationIdQueryUrl <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">&quot;doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/substring(@href,18)&quot;</span>);
     <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> stationNameQueryUrl <span class="operator">=</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">&quot;doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/string()&quot;</span>);

     <span class="type"><a href="qstringlist.html">QStringList</a></span> stationIds;
     <span class="type"><a href="qstringlist.html">QStringList</a></span> stationNames;

     <span class="type"><a href="qxmlquery.html">QXmlQuery</a></span> query;

     query<span class="operator">.</span>bindVariable(<span class="string">&quot;station&quot;</span><span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="type"><a href="qstring.html">QString</a></span><span class="operator">::</span>fromLatin1(<span class="type"><a href="qurl.html">QUrl</a></span><span class="operator">::</span>toPercentEncoding(name))));
     query<span class="operator">.</span>setQuery(stationIdQueryUrl);
     query<span class="operator">.</span>evaluateTo(<span class="operator">&amp;</span>stationIds);

     query<span class="operator">.</span>bindVariable(<span class="string">&quot;station&quot;</span><span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="type"><a href="qstring.html">QString</a></span><span class="operator">::</span>fromLatin1(<span class="type"><a href="qurl.html">QUrl</a></span><span class="operator">::</span>toPercentEncoding(name))));
     query<span class="operator">.</span>setQuery(stationNameQueryUrl);
     query<span class="operator">.</span>evaluateTo(<span class="operator">&amp;</span>stationNames);

     <span class="keyword">if</span> (stationIds<span class="operator">.</span>count() <span class="operator">!</span><span class="operator">=</span> stationNames<span class="operator">.</span>count()) <span class="comment">// something went wrong...</span>
         <span class="keyword">return</span> StationInformation<span class="operator">::</span>List();

     StationInformation<span class="operator">::</span>List information;
     <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> stationIds<span class="operator">.</span>count(); <span class="operator">+</span><span class="operator">+</span>i)
         information<span class="operator">.</span>append(StationInformation(stationIds<span class="operator">.</span>at(i)<span class="operator">,</span> stationNames<span class="operator">.</span>at(i)));

     <span class="keyword">return</span> information;
 }</pre>
<p>Just as in the <tt>TimeQuery</tt> implementation, the first step is to synthesize the <a href="xmlprocessing.html">XQuery</a> strings for selecting the station names and the station IDs. As the station name that we pass in the URL will be input from the user, we should protect the <a href="xmlprocessing.html">XQuery</a> from code injection by using the <a href="qxmlquery.html#bindVariable">QXmlQuery::bindVariable</a>() method to do proper quoting of the variable content for us instead of concatenating the two strings manually.</p>
<p>So, we define a <a href="xmlprocessing.html">XQuery</a> <tt>$station</tt> variable that is bound to the user input. This variable is concatenated inside the <a href="xmlprocessing.html">XQuery</a> code with the <tt>concat</tt> method. To extract the station IDs, we select all <tt>a</tt> elements that have an <tt>title</tt> attribute with the content &quot;Velg&quot;, and from these elements we take the substring of the <tt>href</tt> attribute that starts at the 18th character.</p>
<p>The station name can be extracted a bit more easily by just taking the text elements of the selected <i>elements</i>.</p>
<p>After some sanity checks we have all the station IDs and the corresponding names available.</p>
<p>The rest of the code in this example is just for representing the time and station information to the user, and uses techniques described in the <a href="examples-widgets.html">Widget Examples</a>.</p>
</div>
<!-- @@@xmlpatterns/trafficinfo -->
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Qt and respective logos are trademarks of The Qt Company Ltd 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>