Qt Mobility Reference Documentation

Query Messages Example

Files:

This simple example shows how to query messages stored in the system, using the Qt Mobility Messaging API.

Messages are queried by using the QMessageManager interface which provides access to the message data stored in the system. We will use the queryMessages function to locate messages that match a filter object which defines the properties of the messages we would like to find.

We define our query properties like this:

     // Create filter to match required messages
     QMessageFilter filter = createFilter(app.arguments());
     // 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
     //QMessageFilter filter(QMessageFilter::byStatus(QMessage::Incoming));

     // Order the matching results by their reception timestamp, in descending order
     QMessageSortOrder sortOrder(QMessageSortOrder::byReceptionTimeStamp(Qt::DescendingOrder));

Then we use these properties to extract the set of matching message identifiers from the QMessageManager instance:

     // Acquire a handle to the message manager
     QMessageManager manager;

     // Find the matching message IDs, limiting our results to a managable number
     const int max = 100;
     const QMessageIdList matchingIds(manager.queryMessages(filter, sortOrder, max));

Now we can iterate over our list of message identifiers, retrieving a QMessage instance containing the details of each message in turn:

     // Retrieve each message and print requested details
     foreach (const QMessageId &id, matchingIds) {
         QMessage message(manager.message(id));

For each message we located, we now generate an output element corresponding to each data item requested at the command line:

             // Extract the requested data items from this message
             foreach (const QString &arg, dataOptions) {
                 if (arg == "subject") {
                     result.append(message.subject());
                 } else if (arg == "date") {
                     result.append(message.date().toLocalTime().toString());

Finally, we print the results accumulated for each message that matched our query.

             printMessage(QString::number(++n) + '\t' + result.join("\t"));
X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.