Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 50facae208d4a6f280e44a513b104320 > files > 1748

qt-mobility-doc-1.2.0-13.mga5.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" />
<!-- querymessages.qdoc -->
  <title>Qt Mobility 1.2: Query Messages Example</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>QtMobility Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="http://qt.nokia.com/doc/4.7/all-examples.html">Examples</a></li>
<li>Query Messages Example</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<h1 class="title">Query Messages Example</h1>
<span class="subtitle"></span>
<!-- $$$querymessages-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="querymessages-main-cpp.html">querymessages/main.cpp</a></li>
<li><a href="querymessages-querymessages-pro.html">querymessages/querymessages.pro</a></li>
</ul>
<p>This simple example shows how to query messages stored in the system, using the QtMobility Messaging API.</p>
<p>Messages are queried by using the <a href="qmessagemanager.html">QMessageManager</a> interface which provides access to the message data stored in the system. We will use the <a href="qmessagemanager.html#queryMessages">queryMessages</a> function to locate messages that match a filter object which defines the properties of the messages we would like to find.</p>
<p>We define our query properties like this:</p>
<pre class="cpp">     <span class="comment">// Create filter to match required messages</span>
     <span class="type"><a href="qmessagefilter.html">QMessageFilter</a></span> filter <span class="operator">=</span> createFilter(app<span class="operator">.</span>arguments());
     <span class="comment">// instead of the above use the following for a simple filter of all messages whose status field have the Incoming flag to be set, eg incoming emails</span>
     <span class="comment">//QMessageFilter filter(QMessageFilter::byStatus(QMessage::Incoming));</span>

     <span class="comment">// Order the matching results by their reception timestamp, in descending order</span>
     <span class="type"><a href="qmessagesortorder.html">QMessageSortOrder</a></span> sortOrder(<span class="type"><a href="qmessagesortorder.html">QMessageSortOrder</a></span><span class="operator">::</span>byReceptionTimeStamp(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qt.html">Qt</a></span><span class="operator">::</span>DescendingOrder));</pre>
<p>Then we use these properties to extract the set of matching message identifiers from the <a href="qmessagemanager.html">QMessageManager</a> instance:</p>
<pre class="cpp">     <span class="comment">// Acquire a handle to the message manager</span>
     <span class="type"><a href="qmessagemanager.html">QMessageManager</a></span> manager;

     <span class="comment">// Find the matching message IDs, limiting our results to a managable number</span>
     <span class="keyword">const</span> <span class="type">int</span> max <span class="operator">=</span> <span class="number">100</span>;
     <span class="keyword">const</span> <span class="type">QMessageIdList</span> matchingIds(manager<span class="operator">.</span>queryMessages(filter<span class="operator">,</span> sortOrder<span class="operator">,</span> max));</pre>
<p>Now we can iterate over our list of message identifiers, retrieving a <a href="qmessage.html">QMessage</a> instance containing the details of each message in turn:</p>
<pre class="cpp">     <span class="comment">// Retrieve each message and print requested details</span>
     foreach (<span class="keyword">const</span> <span class="type"><a href="qmessageid.html">QMessageId</a></span> <span class="operator">&amp;</span>id<span class="operator">,</span> matchingIds) {
         <span class="type"><a href="qmessage.html">QMessage</a></span> message(manager<span class="operator">.</span>message(id));</pre>
<p>For each message we located, we now generate an output element corresponding to each data item requested at the command line:</p>
<pre class="cpp">             <span class="comment">// Extract the requested data items from this message</span>
             foreach (<span class="keyword">const</span> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span> <span class="operator">&amp;</span>arg<span class="operator">,</span> dataOptions) {
                 <span class="keyword">if</span> (arg <span class="operator">=</span><span class="operator">=</span> <span class="string">&quot;subject&quot;</span>) {
                     result<span class="operator">.</span>append(message<span class="operator">.</span>subject());
                 } <span class="keyword">else</span> <span class="keyword">if</span> (arg <span class="operator">=</span><span class="operator">=</span> <span class="string">&quot;date&quot;</span>) {
                     result<span class="operator">.</span>append(message<span class="operator">.</span>date()<span class="operator">.</span>toLocalTime()<span class="operator">.</span>toString());</pre>
<p>Finally, we print the results accumulated for each message that matched our query.</p>
<pre class="cpp">             printMessage(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span><span class="operator">::</span>number(<span class="operator">+</span><span class="operator">+</span>n) <span class="operator">+</span> <span class="char">'\t'</span> <span class="operator">+</span> result<span class="operator">.</span>join(<span class="string">&quot;\t&quot;</span>));</pre>
</div>
<!-- @@@querymessages -->
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
  <p>
     <acronym title="Copyright">&copy;</acronym> 2008-2011 Nokia Corporation and/or its
     subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
     in Finland and/or other countries worldwide.</p>
  <p>
     All other trademarks are property of their respective owners. <a title="Privacy Policy"
     href="http://qt.nokia.com/about/privacy-policy">Privacy Policy</a></p>
  <br />
  <p>
    Licensees holding valid Qt Commercial licenses may use this document in accordance with the    Qt Commercial License Agreement provided with the Software or, alternatively, in accordance    with the terms contained in a written agreement between you and Nokia.</p>
  <p>
    Alternatively, this document may be used 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>
</div>
</body>
</html>