![]() |
Home · All Classes · All Functions · | ![]() |
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:
// Match all messages whose status field includes the Incoming flag 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, app.arguments().mid(1)) {
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"));
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Mobility Project 1.0.2 |